Skip to content

Commit

Permalink
Eoxia#61 [Block] add: files for the new categories list block
Browse files Browse the repository at this point in the history
  • Loading branch information
eoxia-amandine committed Aug 30, 2024
1 parent 976a797 commit fc0e952
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ var scss_paths = [
'inc/blocks/bfs-course-tax/assets/scss/**/*.scss',
'inc/blocks/bfs-course-lesson/assets/scss/**/*.scss',
'inc/blocks/bfs-course-time/assets/scss/**/*.scss',
'inc/blocks/bfs-login/assets/scss/**/*.scss'
'inc/blocks/bfs-login/assets/scss/**/*.scss',
'inc/blocks/bfs-list-course-category/assets/scss/**/*.scss'

];

/** SCSS */
Expand Down
23 changes: 23 additions & 0 deletions inc/blocks/bfs-list-course-category/assets/json/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"name": "beflex/list-course-category",
"title": "BFS List Course Category",
"description": "",
"style": [ "block-bfs-list-course-category-style" ],
"viewScript": [],
"category": "beflex",
"icon": "",
"apiVersion": 2,
"textdomain": "beflex",
"keywords": [
"beflex",
"bfs",
"list-course-category"
],
"supports": {
},
"acf": {
"mode": "auto",
"renderTemplate": "../../view.php"
}
}
3 changes: 3 additions & 0 deletions inc/blocks/bfs-list-course-category/assets/scss/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/**
* Style CSS de bfs-list-course-category
*/
41 changes: 41 additions & 0 deletions inc/blocks/bfs-list-course-category/bfs-list-course-category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* list-course-category
*
* @author Eoxia <[email protected]>
* @link https://developer.wordpress.org/themes/basics/theme-functions/
* @since 4.0.0
* @package beflex-child
*
*/

if ( ! defined( 'BFS_LIST_COURSE_CATEGORY_DIR' ) ) {
define( 'BFS_LIST_COURSE_CATEGORY_DIR', dirname(__DIR__, 1) . '/bfs-list-course-category' );
}
if ( ! defined( 'BFS_LIST_COURSE_CATEGORY_URL' ) ) {
define( 'BFS_LIST_COURSE_CATEGORY_URL', get_template_directory_uri() . '/inc/blocks/bfs-list-course-category' );
}

/**
* Generate block
*
* @return void
*/
function bfs_list_course_category_register_acf_blocks() {
wp_register_style( 'block-bfs-list-course-category-style', BFS_LIST_COURSE_CATEGORY_URL . '/assets/css/style.min.css' );
register_block_type( BFS_LIST_COURSE_CATEGORY_DIR . '/assets/json/' );
}
add_action( 'init', 'bfs_list_course_category_register_acf_blocks', 5 );

/**
* Load Json fields
*
* @param array $paths Json path
*
* @return array $paths Json path
*/
function bfs_list_course_category_load_json( $paths ) {
$paths[] = BFS_LIST_COURSE_CATEGORY_DIR . '/assets/json';
return $paths;
}
add_filter( 'acf/settings/load_json', 'bfs_list_course_category_load_json' );
38 changes: 38 additions & 0 deletions inc/blocks/bfs-list-course-category/view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* list-course-category.
*
* @param array $block The block settings and attributes.
* @param string $content The block inner HTML (empty).
* @param bool $is_preview True during backend preview render.
* @param int $post_id The post ID the block is rendering content against.
* This is either the post ID currently being displayed inside a query loop,
* or the post ID of the post hosting this block.
* @param array $context The context provided to the block by the post or its parent block.
*/

// Support custom "anchor" values.
$anchor = '';
if ( ! empty( $block['anchor'] ) ) {
$anchor = 'id="' . esc_attr( $block['anchor'] ) . '" ';
}

// Create class attribute allowing for custom "className" and "align" values.
$class_name = 'bfs-list-course-category';

if ( ! empty( $block['className'] ) ) {
$class_name .= ' ' . $block['className'];
}
if ( ! empty( $block['align'] ) ) {
$class_name .= ' align' . $block['align'];
}

// Admin classes
if ( is_admin() ) :
$class_name .= ' is-admin';
endif;
?>

<div <?php echo $anchor; ?> class="<?php echo esc_attr( $class_name ); ?>">
COucou
</div>

0 comments on commit fc0e952

Please sign in to comment.