From de5262393ca74a542e1eea04ea8c48ed4c270e7d Mon Sep 17 00:00:00 2001 From: Ella <4710635+ellatrix@users.noreply.github.com> Date: Mon, 11 Nov 2024 10:44:50 +0100 Subject: [PATCH] Inserter: Add 'Starter Content' category to the inserter (#66819) Co-authored-by: ellatrix Co-authored-by: youknowriad Co-authored-by: carolinan --- .../block-patterns-tab/pattern-category-previews.js | 8 ++++++++ .../inserter/block-patterns-tab/use-pattern-categories.js | 8 ++++++++ .../src/components/inserter/block-patterns-tab/utils.js | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/packages/block-editor/src/components/inserter/block-patterns-tab/pattern-category-previews.js b/packages/block-editor/src/components/inserter/block-patterns-tab/pattern-category-previews.js index 2c5d96d5ff973..a19a579ae5c0c 100644 --- a/packages/block-editor/src/components/inserter/block-patterns-tab/pattern-category-previews.js +++ b/packages/block-editor/src/components/inserter/block-patterns-tab/pattern-category-previews.js @@ -31,6 +31,7 @@ import { isPatternFiltered, allPatternsCategory, myPatternsCategory, + starterPatternsCategory, INSERTER_PATTERN_TYPES, } from './utils'; import { store as blockEditorStore } from '../../../store'; @@ -86,6 +87,13 @@ export function PatternCategoryPreviews( { return true; } + if ( + category.name === starterPatternsCategory.name && + pattern.blockTypes?.includes( 'core/post-content' ) + ) { + return true; + } + if ( category.name === 'uncategorized' ) { // The uncategorized category should show all the patterns without any category... if ( ! pattern.categories ) { diff --git a/packages/block-editor/src/components/inserter/block-patterns-tab/use-pattern-categories.js b/packages/block-editor/src/components/inserter/block-patterns-tab/use-pattern-categories.js index cff5fbf341382..2adc6b48579dd 100644 --- a/packages/block-editor/src/components/inserter/block-patterns-tab/use-pattern-categories.js +++ b/packages/block-editor/src/components/inserter/block-patterns-tab/use-pattern-categories.js @@ -14,6 +14,7 @@ import { isPatternFiltered, allPatternsCategory, myPatternsCategory, + starterPatternsCategory, INSERTER_PATTERN_TYPES, } from './utils'; @@ -67,6 +68,13 @@ export function usePatternCategories( rootClientId, sourceFilter = 'all' ) { label: _x( 'Uncategorized' ), } ); } + if ( + filteredPatterns.some( ( pattern ) => + pattern.blockTypes?.includes( 'core/post-content' ) + ) + ) { + categories.unshift( starterPatternsCategory ); + } if ( filteredPatterns.some( ( pattern ) => pattern.type === INSERTER_PATTERN_TYPES.user diff --git a/packages/block-editor/src/components/inserter/block-patterns-tab/utils.js b/packages/block-editor/src/components/inserter/block-patterns-tab/utils.js index f8ba47f3790e1..58065ac33ad2b 100644 --- a/packages/block-editor/src/components/inserter/block-patterns-tab/utils.js +++ b/packages/block-editor/src/components/inserter/block-patterns-tab/utils.js @@ -25,6 +25,11 @@ export const myPatternsCategory = { label: __( 'My patterns' ), }; +export const starterPatternsCategory = { + name: 'core/starter-content', + label: __( 'Starter Content' ), +}; + export function isPatternFiltered( pattern, sourceFilter, syncFilter ) { const isUserPattern = pattern.name.startsWith( 'core/block' ); const isDirectoryPattern =