Skip to content

Commit

Permalink
Add: Post type restriction API for patterns. (#41842)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta authored Sep 7, 2022
1 parent 0d0ed17 commit 671e436
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
18 changes: 13 additions & 5 deletions packages/edit-site/src/components/block-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,19 @@ export default function BlockEditor( { setIsInserterOpen } ) {
[
...( settingsBlockPatterns || [] ),
...( restBlockPatterns || [] ),
].filter(
( x, index, arr ) =>
index === arr.findIndex( ( y ) => x.name === y.name )
),
[ settingsBlockPatterns, restBlockPatterns ]
]
.filter(
( x, index, arr ) =>
index === arr.findIndex( ( y ) => x.name === y.name )
)
.filter( ( { postTypes } ) => {
return (
! postTypes ||
( Array.isArray( postTypes ) &&
postTypes.includes( templateType ) )
);
} ),
[ settingsBlockPatterns, restBlockPatterns, templateType ]
);

const blockPatternCategories = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ function useBlockEditorSettings( settings, hasTemplate ) {
canUseUnfilteredHTML,
userCanCreatePages,
pageOnFront,
postType,
} = useSelect( ( select ) => {
const { canUserUseUnfilteredHTML } = select( editorStore );
const { canUserUseUnfilteredHTML, getCurrentPostType } =
select( editorStore );
const isWeb = Platform.OS === 'web';
const { canUser, getEntityRecord } = select( coreStore );

Expand All @@ -57,6 +59,7 @@ function useBlockEditorSettings( settings, hasTemplate ) {
hasUploadPermissions: canUser( 'create', 'media' ) ?? true,
userCanCreatePages: canUser( 'create', 'pages' ),
pageOnFront: siteSettings?.page_on_front,
postType: getCurrentPostType(),
};
}, [] );

Expand All @@ -81,11 +84,19 @@ function useBlockEditorSettings( settings, hasTemplate ) {
[
...( settingsBlockPatterns || [] ),
...( restBlockPatterns || [] ),
].filter(
( x, index, arr ) =>
index === arr.findIndex( ( y ) => x.name === y.name )
),
[ settingsBlockPatterns, restBlockPatterns ]
]
.filter(
( x, index, arr ) =>
index === arr.findIndex( ( y ) => x.name === y.name )
)
.filter( ( { postTypes } ) => {
return (
! postTypes ||
( Array.isArray( postTypes ) &&
postTypes.includes( postType ) )
);
} ),
[ settingsBlockPatterns, restBlockPatterns, postType ]
);

const blockPatternCategories = useMemo(
Expand Down

0 comments on commit 671e436

Please sign in to comment.