Skip to content

Commit

Permalink
Use context to get the postType
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinan committed Nov 6, 2023
1 parent c94aecb commit 54a58bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/block-library/src/post-navigation-link/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"default": ""
}
},
"usesContext": [ "postType" ],
"supports": {
"reusable": false,
"html": false,
Expand Down
15 changes: 6 additions & 9 deletions packages/block-library/src/post-navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';

export default function PostNavigationLinkEdit( {
context: { postType },
attributes: {
type,
label,
Expand Down Expand Up @@ -59,14 +60,6 @@ export default function PostNavigationLinkEdit( {
} ),
} );

// We need to know the post type in order to get all supported taxonomies.
const postType = useSelect(
// FIXME: @wordpress/block-library should not depend on @wordpress/editor.
// Blocks can be loaded into a *non-post* block editor.
// eslint-disable-next-line @wordpress/data-no-store-string-literals
( select ) => select( 'core/editor' ).getCurrentPostType(),
[]
);
const taxonomies = useSelect(
( select ) => {
const { getTaxonomies } = select( coreStore );
Expand All @@ -85,7 +78,11 @@ export default function PostNavigationLinkEdit( {
value: '',
};
const taxonomyOptions = ( taxonomies ?? [] )
.filter( ( tax ) => tax.slug !== 'nav_menu' )
.filter(
( tax ) =>
tax.slug !== 'nav_menu' &&
tax.slug !== 'wp_pattern_category'
)
.map( ( item ) => {
return {
value: item.slug,
Expand Down

0 comments on commit 54a58bb

Please sign in to comment.