Skip to content

Commit

Permalink
Add "theme" category and better present template parts in the inserter (
Browse files Browse the repository at this point in the history
#30020)

* Introduce "theme" category for blocks.
* Assign template-part block to "theme" category.
* Use layout icon for template parts.
* Make header and footer variations available in the inserter.
  • Loading branch information
mtias authored Mar 19, 2021
1 parent a4b2b42 commit 6ad2a43
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
17 changes: 17 additions & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,20 @@ function gutenberg_register_legacy_social_link_blocks() {
}

add_action( 'init', 'gutenberg_register_legacy_social_link_blocks' );

/**
* Filters the default block categories array to add a new one for themes.
* Should be removed and turned into a core.trac ticket for merge.
*
* @param array $categories The list of default block categories.
*/
function gutenberg_register_theme_block_category( $categories ) {
$categories[] = array(
'slug' => 'theme',
'title' => _x( 'Theme', 'block category' ),
'icon' => null,
);
return $categories;
}

add_filter( 'block_categories', 'gutenberg_register_theme_block_category' );
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const categories = [
{ slug: 'media', title: 'Media' },
{ slug: 'design', title: 'Design' },
{ slug: 'widgets', title: 'Widgets' },
{ slug: 'theme', title: 'Theme' },
{ slug: 'embed', title: 'Embeds' },
{ slug: 'reusable', title: 'Reusable blocks' },
];
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/template-part/block.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"apiVersion": 2,
"name": "core/template-part",
"category": "design",
"category": "theme",
"attributes": {
"slug": {
"type": "string"
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/template-part/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { startCase } from 'lodash';
import { store as coreDataStore } from '@wordpress/core-data';
import { select } from '@wordpress/data';
import { __, _x } from '@wordpress/i18n';
import { layout } from '@wordpress/icons';

/**
* Internal dependencies
Expand All @@ -25,6 +26,7 @@ export const settings = {
description: __(
'Edit the different global regions of your site, like the header, footer, sidebar, or create your own.'
),
icon: layout,
keywords: [ __( 'template part' ) ],
__experimentalLabel: ( { slug, theme } ) => {
// Attempt to find entity title if block is a template part.
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/template-part/variations.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const variations = [
),
icon: header,
isActive: createIsActiveBasedOnArea( 'header' ),
scope: [],
scope: [ 'inserter' ],
},
{
name: 'footer',
Expand All @@ -39,7 +39,7 @@ const variations = [
),
icon: footer,
isActive: createIsActiveBasedOnArea( 'footer' ),
scope: [],
scope: [ 'inserter' ],
},
];

Expand Down
1 change: 1 addition & 0 deletions packages/blocks/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const DEFAULT_CATEGORIES = [
{ slug: 'media', title: __( 'Media' ) },
{ slug: 'design', title: __( 'Design' ) },
{ slug: 'widgets', title: __( 'Widgets' ) },
{ slug: 'theme', title: __( 'Theme' ) },
{ slug: 'embed', title: __( 'Embeds' ) },
{ slug: 'reusable', title: __( 'Reusable blocks' ) },
];
Expand Down

0 comments on commit 6ad2a43

Please sign in to comment.