Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Add isNavigationBlock utility to identify navigation blocks #68647

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
store as blocksStore,
isReusableBlock,
isTemplatePart,
isNavigationBlock,
__experimentalGetBlockLabel as getBlockLabel,
} from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
Expand Down Expand Up @@ -83,7 +84,9 @@ export default function useBlockDisplayInformation( clientId ) {
const attributes = getBlockAttributes( clientId );
const match = getActiveBlockVariation( blockName, attributes );
const isSynced =
isReusableBlock( blockType ) || isTemplatePart( blockType );
isReusableBlock( blockType ) ||
isTemplatePart( blockType ) ||
isNavigationBlock( blockType );
const syncedTitle = isSynced
? getBlockLabel( blockType, attributes )
: undefined;
Expand Down
12 changes: 12 additions & 0 deletions packages/blocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,18 @@ _Returns_

- `boolean`: True if a block contains at least one child blocks with inserter support and false otherwise.

### isNavigationBlock

Determines whether or not the given block is a navigation block. This is a special block type that is used to represent a navigation menu.

_Parameters_

- _blockOrType_ `Object`: Block or Block Type to test.

_Returns_

- `boolean`: Whether the given block is a navigation block.

### isReusableBlock

Determines whether or not the given block is a reusable block. This is a special block type that is used to point to a global block stored via the API.
Expand Down
1 change: 1 addition & 0 deletions packages/blocks/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export {
getBlockVariations,
isReusableBlock,
isTemplatePart,
isNavigationBlock,
getChildBlockNames,
hasChildBlocks,
hasChildBlocksWithInserterSupport,
Expand Down
12 changes: 12 additions & 0 deletions packages/blocks/src/api/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,18 @@ export function isTemplatePart( blockOrType ) {
return blockOrType?.name === 'core/template-part';
}

/**
* Determines whether or not the given block is a navigation block. This is a
* special block type that is used to represent a navigation menu.
*
* @param {Object} blockOrType Block or Block Type to test.
*
* @return {boolean} Whether the given block is a navigation block.
*/
export function isNavigationBlock( blockOrType ) {
return blockOrType?.name === 'core/navigation';
}

/**
* Returns an array with the child blocks of a given block.
*
Expand Down
Loading