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

[WIP] Allow setting allowedBlocks on Navigation block via attribute #52467

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ A collection of blocks that allow visitors to get around your site. ([Source](ht
- **Name:** core/navigation
- **Category:** theme
- **Supports:** align (full, wide), inserter, interactivity, layout (allowSizingOnChildren, default, ~~allowInheriting~~, ~~allowSwitching~~, ~~allowVerticalAlignment~~), spacing (blockGap, units), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** __unstableLocation, backgroundColor, customBackgroundColor, customOverlayBackgroundColor, customOverlayTextColor, customTextColor, hasIcon, icon, maxNestingLevel, openSubmenusOnClick, overlayBackgroundColor, overlayMenu, overlayTextColor, ref, rgbBackgroundColor, rgbTextColor, showSubmenuIcon, templateLock, textColor
- **Attributes:** __unstableLocation, allowedBlocks, backgroundColor, customBackgroundColor, customOverlayBackgroundColor, customOverlayTextColor, customTextColor, hasIcon, icon, maxNestingLevel, openSubmenusOnClick, overlayBackgroundColor, overlayMenu, overlayTextColor, ref, rgbBackgroundColor, rgbTextColor, showSubmenuIcon, templateLock, textColor

## Custom Link

Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/navigation/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
"templateLock": {
"type": [ "string", "boolean" ],
"enum": [ "all", "insert", "contentOnly", false ]
},
"allowedBlocks": {
"type": "array"
}
},
"providesContext": {
Expand Down
5 changes: 5 additions & 0 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ import ManageMenusButton from './manage-menus-button';
import MenuInspectorControls from './menu-inspector-controls';
import DeletedNavigationWarning from './deleted-navigation-warning';
import { unlock } from '../../lock-unlock';
import { ALLOWED_BLOCKS } from '../constants';

const { useBlockEditingMode } = unlock( blockEditorPrivateApis );

function Navigation( {
Expand Down Expand Up @@ -103,6 +105,7 @@ function Navigation( {
} = {},
hasIcon,
icon = 'handle',
allowedBlocks = ALLOWED_BLOCKS,
} = attributes;

const ref = attributes.ref;
Expand Down Expand Up @@ -675,6 +678,7 @@ function Navigation( {
createNavigationMenu={ createNavigationMenu }
blocks={ uncontrolledInnerBlocks }
hasSelection={ isSelected || isInnerBlockSelected }
allowedBlocks={ allowedBlocks }
/>
</ResponsiveWrapper>
</TagName>
Expand Down Expand Up @@ -830,6 +834,7 @@ function Navigation( {
}
templateLock={ templateLock }
orientation={ orientation }
allowedBlocks={ allowedBlocks }
/>
) }
</ResponsiveWrapper>
Expand Down
9 changes: 3 additions & 6 deletions packages/block-library/src/navigation/edit/inner-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ import { useMemo } from '@wordpress/element';
* Internal dependencies
*/
import PlaceholderPreview from './placeholder/placeholder-preview';
import {
DEFAULT_BLOCK,
ALLOWED_BLOCKS,
PRIORITIZED_INSERTER_BLOCKS,
} from '../constants';
import { DEFAULT_BLOCK, PRIORITIZED_INSERTER_BLOCKS } from '../constants';

export default function NavigationInnerBlocks( {
clientId,
hasCustomPlaceholder,
orientation,
templateLock,
allowedBlocks,
} ) {
const {
isImmediateParentOfSelectedBlock,
Expand Down Expand Up @@ -96,7 +93,7 @@ export default function NavigationInnerBlocks( {
value: blocks,
onInput,
onChange,
allowedBlocks: ALLOWED_BLOCKS,
allowedBlocks,
prioritizedInserterBlocks: PRIORITIZED_INSERTER_BLOCKS,
__experimentalDefaultBlock: DEFAULT_BLOCK,
__experimentalDirectInsert: shouldDirectInsert,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ import { useContext, useEffect, useRef, useMemo } from '@wordpress/element';
* Internal dependencies
*/
import { areBlocksDirty } from './are-blocks-dirty';
import {
DEFAULT_BLOCK,
ALLOWED_BLOCKS,
SELECT_NAVIGATION_MENUS_ARGS,
} from '../constants';
import { DEFAULT_BLOCK, SELECT_NAVIGATION_MENUS_ARGS } from '../constants';

const EMPTY_OBJECT = {};

export default function UnsavedInnerBlocks( {
blocks,
createNavigationMenu,
hasSelection,
allowedBlocks,
} ) {
const originalBlocks = useRef();

Expand Down Expand Up @@ -67,7 +64,7 @@ export default function UnsavedInnerBlocks( {
},
{
renderAppender: hasSelection ? undefined : false,
allowedBlocks: ALLOWED_BLOCKS,
allowedBlocks,
__experimentalDefaultBlock: DEFAULT_BLOCK,
__experimentalDirectInsert: shouldDirectInsert,
}
Expand Down