From 43c08b9ae3875473e1ed464ac14aeccbdadd0a66 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 19 Jan 2023 17:29:38 +0800 Subject: [PATCH 1/6] Naive implementation --- lib/compat/wordpress-6.2/block-patterns.php | 1 + ...g-rest-block-pattern-categories-controller.php | 8 +++++++- .../provider/use-block-editor-settings.js | 15 +++++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/compat/wordpress-6.2/block-patterns.php b/lib/compat/wordpress-6.2/block-patterns.php index 13d9af9622049..0fe661eee56c6 100644 --- a/lib/compat/wordpress-6.2/block-patterns.php +++ b/lib/compat/wordpress-6.2/block-patterns.php @@ -135,6 +135,7 @@ function gutenberg_register_core_block_patterns_categories() { array( 'label' => _x( 'Headers', 'Block pattern category', 'gutenberg' ), 'description' => __( 'A variety of header designs displaying your site title and navigation.', 'gutenberg' ), + 'editors' => array( 'core/site' ), ) ); } diff --git a/lib/compat/wordpress-6.2/class-gutenberg-rest-block-pattern-categories-controller.php b/lib/compat/wordpress-6.2/class-gutenberg-rest-block-pattern-categories-controller.php index 970b1c4a1a330..aaed56c922899 100644 --- a/lib/compat/wordpress-6.2/class-gutenberg-rest-block-pattern-categories-controller.php +++ b/lib/compat/wordpress-6.2/class-gutenberg-rest-block-pattern-categories-controller.php @@ -25,7 +25,7 @@ class Gutenberg_REST_Block_Pattern_Categories_Controller extends WP_REST_Block_P */ public function prepare_item_for_response( $item, $request ) { $fields = $this->get_fields_for_response( $request ); - $keys = array( 'name', 'label', 'description' ); + $keys = array( 'name', 'label', 'description', 'editors' ); $data = array(); foreach ( $keys as $key ) { if ( isset( $item[ $key ] ) && rest_is_field_included( $key, $fields ) ) { @@ -70,6 +70,12 @@ public function get_item_schema() { 'readonly' => true, 'context' => array( 'view', 'edit', 'embed' ), ), + 'editors' => array( + 'description' => __( 'The editors this category is allowed to be shown on.', 'gutenberg' ), + 'type' => 'array', + 'readonly' => true, + 'context' => array( 'view', 'edit', 'embed' ), + ), ), ); diff --git a/packages/editor/src/components/provider/use-block-editor-settings.js b/packages/editor/src/components/provider/use-block-editor-settings.js index a914602db45e8..e3c94e58b11c8 100644 --- a/packages/editor/src/components/provider/use-block-editor-settings.js +++ b/packages/editor/src/components/provider/use-block-editor-settings.js @@ -102,10 +102,17 @@ function useBlockEditorSettings( settings, hasTemplate ) { [ ...( settingsBlockPatternCategories || [] ), ...( restBlockPatternCategories || [] ), - ].filter( - ( x, index, arr ) => - index === arr.findIndex( ( y ) => x.name === y.name ) - ), + ] + .filter( + ( x, index, arr ) => + index === arr.findIndex( ( y ) => x.name === y.name ) + ) + .filter( ( cat ) => { + if ( ! cat?.editors?.length ) { + return true; + } + return cat.editors.includes( 'core/post' ); + } ), [ settingsBlockPatternCategories, restBlockPatternCategories ] ); From 8b324441540080c284f9d3c324e526ab21fd6142 Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Tue, 24 Jan 2023 11:14:11 +0000 Subject: [PATCH 2/6] Tweak comments --- lib/compat/wordpress-6.2/block-patterns.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/compat/wordpress-6.2/block-patterns.php b/lib/compat/wordpress-6.2/block-patterns.php index 0fe661eee56c6..13c48bb9ff92c 100644 --- a/lib/compat/wordpress-6.2/block-patterns.php +++ b/lib/compat/wordpress-6.2/block-patterns.php @@ -9,6 +9,8 @@ * Registers the block pattern categories. */ function gutenberg_register_core_block_patterns_categories() { + // Register universal block pattern categories + // Available in post and site editor. register_block_pattern_category( 'banner', array( @@ -51,7 +53,8 @@ function gutenberg_register_core_block_patterns_categories() { ) ); - // Register new core block pattern categories. + // Register new universal core block pattern categories. + // Available in post and site editor. register_block_pattern_category( 'call-to-action', array( @@ -122,7 +125,9 @@ function gutenberg_register_core_block_patterns_categories() { 'description' => __( 'Display your latest posts in lists, grids or other layouts.', 'gutenberg' ), ) ); - // Site building pattern categories. + + // Register site building pattern categories. + // Available in site editor. register_block_pattern_category( 'footer', array( From 683f4bca3929c9b21b65bb1ecea87e3f7fd5196c Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Tue, 24 Jan 2023 11:14:30 +0000 Subject: [PATCH 3/6] Add description to Banner category --- lib/compat/wordpress-6.2/block-patterns.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/compat/wordpress-6.2/block-patterns.php b/lib/compat/wordpress-6.2/block-patterns.php index 13c48bb9ff92c..b04592eaa1a8e 100644 --- a/lib/compat/wordpress-6.2/block-patterns.php +++ b/lib/compat/wordpress-6.2/block-patterns.php @@ -15,6 +15,7 @@ function gutenberg_register_core_block_patterns_categories() { 'banner', array( 'label' => _x( 'Banners', 'Block pattern category', 'gutenberg' ), + 'description' => __( 'An element that helps structure or contrast the contents of a page.', 'gutenberg' ), ) ); register_block_pattern_category( From 44118ca4fba30e03d4d05e462b3d78ae5aee7329 Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Tue, 24 Jan 2023 11:14:40 +0000 Subject: [PATCH 4/6] Fix linting --- lib/compat/wordpress-6.2/block-patterns.php | 2 +- ...class-gutenberg-rest-block-pattern-categories-controller.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compat/wordpress-6.2/block-patterns.php b/lib/compat/wordpress-6.2/block-patterns.php index b04592eaa1a8e..f5504114dfd9b 100644 --- a/lib/compat/wordpress-6.2/block-patterns.php +++ b/lib/compat/wordpress-6.2/block-patterns.php @@ -141,7 +141,7 @@ function gutenberg_register_core_block_patterns_categories() { array( 'label' => _x( 'Headers', 'Block pattern category', 'gutenberg' ), 'description' => __( 'A variety of header designs displaying your site title and navigation.', 'gutenberg' ), - 'editors' => array( 'core/site' ), + 'editors' => array( 'core/site' ), ) ); } diff --git a/lib/compat/wordpress-6.2/class-gutenberg-rest-block-pattern-categories-controller.php b/lib/compat/wordpress-6.2/class-gutenberg-rest-block-pattern-categories-controller.php index aaed56c922899..bf9442ec7575b 100644 --- a/lib/compat/wordpress-6.2/class-gutenberg-rest-block-pattern-categories-controller.php +++ b/lib/compat/wordpress-6.2/class-gutenberg-rest-block-pattern-categories-controller.php @@ -70,7 +70,7 @@ public function get_item_schema() { 'readonly' => true, 'context' => array( 'view', 'edit', 'embed' ), ), - 'editors' => array( + 'editors' => array( 'description' => __( 'The editors this category is allowed to be shown on.', 'gutenberg' ), 'type' => 'array', 'readonly' => true, From c41ccb5f790c0c169b791c923e2e99897204bd3b Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Tue, 24 Jan 2023 11:50:23 +0000 Subject: [PATCH 5/6] Add site editor to editors prop for footers --- lib/compat/wordpress-6.2/block-patterns.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/compat/wordpress-6.2/block-patterns.php b/lib/compat/wordpress-6.2/block-patterns.php index f5504114dfd9b..81b2ac07987f8 100644 --- a/lib/compat/wordpress-6.2/block-patterns.php +++ b/lib/compat/wordpress-6.2/block-patterns.php @@ -134,6 +134,7 @@ function gutenberg_register_core_block_patterns_categories() { array( 'label' => _x( 'Footers', 'Block pattern category', 'gutenberg' ), 'description' => __( 'A variety of footer designs displaying information and site navigation.', 'gutenberg' ), + 'editors' => array( 'core/site' ), ) ); register_block_pattern_category( From aa9f19012ec6183d07a04b7fffa654a5b1a5737a Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Tue, 24 Jan 2023 15:32:54 +0000 Subject: [PATCH 6/6] Fix indentation --- lib/compat/wordpress-6.2/block-patterns.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.2/block-patterns.php b/lib/compat/wordpress-6.2/block-patterns.php index 81b2ac07987f8..3c931ca57e9c3 100644 --- a/lib/compat/wordpress-6.2/block-patterns.php +++ b/lib/compat/wordpress-6.2/block-patterns.php @@ -14,7 +14,7 @@ function gutenberg_register_core_block_patterns_categories() { register_block_pattern_category( 'banner', array( - 'label' => _x( 'Banners', 'Block pattern category', 'gutenberg' ), + 'label' => _x( 'Banners', 'Block pattern category', 'gutenberg' ), 'description' => __( 'An element that helps structure or contrast the contents of a page.', 'gutenberg' ), ) );