Skip to content

Commit

Permalink
= 4.2.2.3 =
Browse files Browse the repository at this point in the history
~ Create: archive course, single course blocks Gutenberg.
  • Loading branch information
tungnxt89 committed Mar 28, 2023
1 parent 67639d8 commit 19505b9
Show file tree
Hide file tree
Showing 28 changed files with 188 additions and 137 deletions.
4 changes: 2 additions & 2 deletions assets/src/apps/js/blocks/archive-course/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"name": "learnpress/archive-course",
"title": "Archive Course",
"category": "learnpress-category",
"description": "Renders template Archive property PHP templates.",
"description": "Renders template Archive Course PHP templates.",
"textdomain": "learnpress",
"keywords": [ "archive course", "thim realpress" ],
"keywords": [ "archive course", "learnpress" ],
"usesContext": [],
"supports": {

Expand Down
18 changes: 9 additions & 9 deletions assets/src/apps/js/blocks/archive-course/edit.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import {page} from '@wordpress/icons';
import {__} from '@wordpress/i18n';
import {useBlockProps} from '@wordpress/block-editor';
import {Placeholder} from '@wordpress/components';
import { page } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';
import { useBlockProps } from '@wordpress/block-editor';
import { Placeholder } from '@wordpress/components';

export const edit = (props) => {
export const edit = ( props ) => {
const blockProps = useBlockProps();

return (
<div {...blockProps}>
<div { ...blockProps }>
<Placeholder
icon={page}
label={__('Thim Real Estate Content Archive', 'realpress')}
icon={ page }
label={ __( 'Archive Course', 'learnpress' ) }
>
<div>
{
__(
'This is an editor placeholder for the Archive Property page. Content will render content of list properties. Should be not remove it',
'This is an editor placeholder for the Archive Course page. Content will render content of list courses. Should be not remove it',
'realpress'
)
}
Expand Down
2 changes: 1 addition & 1 deletion assets/src/apps/js/blocks/archive-course/save.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const save = (props) => null;
export const save = ( props ) => null;
10 changes: 0 additions & 10 deletions assets/src/apps/js/blocks/category.js

This file was deleted.

26 changes: 0 additions & 26 deletions assets/src/apps/js/blocks/index.js

This file was deleted.

14 changes: 14 additions & 0 deletions assets/src/apps/js/blocks/item-curriculum-course/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "learnpress/item-curriculum-course",
"title": "Item curriculum Course",
"category": "learnpress-category",
"description": "Renders template Single Item Curriculum Course PHP templates.",
"textdomain": "learnpress",
"keywords": [ "item curriculum course", "learnpress" ],
"usesContext": [],
"supports": {

}
}
26 changes: 26 additions & 0 deletions assets/src/apps/js/blocks/item-curriculum-course/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { page } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';
import { useBlockProps } from '@wordpress/block-editor';
import { Placeholder } from '@wordpress/components';

export const edit = ( props ) => {
const blockProps = useBlockProps();

return (
<div { ...blockProps }>
<Placeholder
icon={ page }
label={ __( 'Item Curriculum Course', 'learnpress' ) }
>
<div>
{
__(
'This is an editor placeholder for the Item Curriculum Course page. Content will render content of single item curriculum course. Should be not remove it',
'learnpress'
)
}
</div>
</Placeholder>
</div>
);
};
13 changes: 13 additions & 0 deletions assets/src/apps/js/blocks/item-curriculum-course/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Register block single course.
*/
import { edit } from './edit';
import { save } from './save';
import block from './block.json';
import { registerBlockType } from '@wordpress/blocks';

registerBlockType( block.name, {
...block,
edit,
save,
} );
1 change: 1 addition & 0 deletions assets/src/apps/js/blocks/item-curriculum-course/save.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const save = ( props ) => null;
14 changes: 14 additions & 0 deletions assets/src/apps/js/blocks/single-course/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "learnpress/single-course",
"title": "Single Course",
"category": "learnpress-category",
"description": "Renders template Single Course PHP templates.",
"textdomain": "learnpress",
"keywords": [ "single course", "learnpress" ],
"usesContext": [],
"supports": {

}
}
26 changes: 26 additions & 0 deletions assets/src/apps/js/blocks/single-course/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { page } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';
import { useBlockProps } from '@wordpress/block-editor';
import { Placeholder } from '@wordpress/components';

export const edit = ( props ) => {
const blockProps = useBlockProps();

return (
<div { ...blockProps }>
<Placeholder
icon={ page }
label={ __( 'Single Course', 'learnpress' ) }
>
<div>
{
__(
'This is an editor placeholder for the Single Course page. Content will render content of single course. Should be not remove it',
'learnpress'
)
}
</div>
</Placeholder>
</div>
);
};
13 changes: 13 additions & 0 deletions assets/src/apps/js/blocks/single-course/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Register block single course.
*/
import { edit } from './edit';
import { save } from './save';
import metadata from './block.json';
import { registerBlockType } from '@wordpress/blocks';

registerBlockType( 'learnpress/single-course', {
...metadata,
edit,
save,
} );
1 change: 1 addition & 0 deletions assets/src/apps/js/blocks/single-course/save.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const save = ( props ) => null;
11 changes: 0 additions & 11 deletions assets/src/apps/js/blocks/template/block.json

This file was deleted.

42 changes: 0 additions & 42 deletions assets/src/apps/js/blocks/template/edit.js

This file was deleted.

19 changes: 0 additions & 19 deletions assets/src/apps/js/blocks/template/index.js

This file was deleted.

4 changes: 3 additions & 1 deletion config/block-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
$blog_template_path = LP_PLUGIN_PATH . 'inc/block-template/';
require_once $blog_template_path . 'class-block-template-archive-course.php';
require_once $blog_template_path . 'class-block-template-single-course.php';
require_once $blog_template_path . 'class-block-template-item-curriculum-course.php';

return apply_filters(
'learn-press/config/block-templates',
array(
new Block_Template_Archive_Course(),
//new Block_Template_Single_Course(),
new Block_Template_Single_Course(),
//new Block_Template_Item_Curriculum_Course(), // When handle item correct post type, uncomment this line, currently item show is post type course.
)
);
10 changes: 7 additions & 3 deletions inc/block-template/class-abstract-block-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ abstract class Abstract_Block_Template extends \WP_Block_Template {
public $has_theme_file = true;
public $is_custom = false;
public $path_html_block_template_file = '';
public $path_template_render_default = '';
/**
* @var string path of the file run js.
*/
public $source_js = '';
/**
* @var bool|string path of the file block.json metadata.
*/
Expand Down Expand Up @@ -56,9 +61,8 @@ public function render_content_block_template( array $attributes ) {

try {
ob_start();
if ( isset( $attributes['template'] ) ) {
Template::instance()->get_frontend_template( $attributes['template'] );
}
$template = $attributes['template'] ?? $this->path_template_render_default;
Template::instance()->get_frontend_template( $template, compact( 'attributes' ) );

$content = ob_get_clean();
} catch ( Throwable $e ) {
Expand Down
2 changes: 2 additions & 0 deletions inc/block-template/class-block-template-archive-course.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Block_Template_Archive_Course extends Abstract_Block_Template {
public $title = 'Course Archive (LearnPress)';
public $description = 'Course Archive Block Template';
public $path_html_block_template_file = 'html/archive-lp_course.html';
public $path_template_render_default = 'archive-course.php';
public $source_js = LP_PLUGIN_URL . 'assets/js/dist/blocks/archive-course.js';

public function __construct() {
parent::__construct();
Expand Down
2 changes: 1 addition & 1 deletion inc/block-template/class-block-template-handle.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function register_tag_block() {
// Register script.
wp_register_script(
$block_template->name, // Block name
LP_PLUGIN_URL . 'assets/js/dist/blocks/archive-course.js', // Block script
$block_template->source_js, // Block script
array( 'wp-blocks', 'wp-editor' ), // Dependencies
uniqid() // Version
);
Expand Down
31 changes: 31 additions & 0 deletions inc/block-template/class-block-template-item-curriculum-course.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* Class Block_Template_Single_Course
*
* Handle register, render block template
*/
class Block_Template_Item_Curriculum_Course extends Abstract_Block_Template {
public $slug = 'item-curriculum-course';
public $name = 'learnpress/item-curriculum-course';
public $title = 'Item curriculum Course (LearnPress)';
public $description = 'Item Curriculum Course Block Template';
public $path_html_block_template_file = 'html/item-curriculum-course.html';
public $path_template_render_default = 'content-single-item.php';
public $source_js = LP_PLUGIN_URL . 'assets/js/dist/blocks/item-curriculum-course.js';

public function __construct() {
parent::__construct();
}

/**
* Render content of block tag
*
* @param array $attributes | Attributes of block tag.
*
* @return false|string
*/
public function render_content_block_template( array $attributes ) {
return parent::render_content_block_template( $attributes );
}
}
13 changes: 12 additions & 1 deletion inc/block-template/class-block-template-single-course.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Block_Template_Single_Course extends Abstract_Block_Template {
public $title = 'Single Course (LearnPress)';
public $description = 'Single Course Block Template';
public $path_html_block_template_file = 'html/single-lp_course.html';
public $path_template_render_default = 'single-course.php';
public $source_js = LP_PLUGIN_URL . 'assets/js/dist/blocks/single-course.js';

public function __construct() {
parent::__construct();
Expand All @@ -24,7 +26,16 @@ public function __construct() {
* @return false|string
*/
public function render_content_block_template( array $attributes ) {
// Debug::var_dump($attributes);
global $wp;
$vars = $wp->query_vars;
// Todo: For item course current display on post_type course
// After when handle display item course on correct post_type item, remove this code.
if ( ! empty( $vars['course-item'] ) ) {
global $post;
setup_postdata( $post );
$this->path_template_render_default = 'content-single-item.php';
}

return parent::render_content_block_template( $attributes );
}
}
2 changes: 2 additions & 0 deletions templates/archive-course.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/

defined( 'ABSPATH' ) || exit;
wp_enqueue_script( 'lp-courses' );
wp_enqueue_style( 'learnpress' );

/**
* @since 4.0.0
Expand Down

0 comments on commit 19505b9

Please sign in to comment.