Skip to content

Commit

Permalink
Don't render unstableLocation if Nav block has ID (#36863)
Browse files Browse the repository at this point in the history
* Don't try and render unstable location if Nav block has ID

* Reinstate condition for empty inner blocks

* Lint

* Show the unstableLocation menu items even if there are inner blocks, as long as there are items at that location.

Co-authored-by: Adam Zieliński <adam@adamziel.com>
Co-authored-by: Ben Dwyer <ben@scruffian.com>
  • Loading branch information
3 people authored Nov 26, 2021
1 parent 96a0daf commit 9ac58ac
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,15 @@ function render_block_core_navigation( $attributes, $content, $block ) {

$inner_blocks = $block->inner_blocks;

// If `__unstableLocation` is defined, create inner blocks from the classic menu assigned to that location.
if ( empty( $inner_blocks ) && array_key_exists( '__unstableLocation', $attributes ) ) {
// If `__unstableLocation` is defined and:
// - we have menu items at the defined location
// - we don't have a relationship to a `wp_navigation` Post (via `navigationMenuId`).
// ...then create inner blocks from the classic menu assigned to that location.
if (
array_key_exists( '__unstableLocation', $attributes ) &&
! array_key_exists( 'navigationMenuId', $attributes ) &&
! empty( gutenberg_get_menu_items_at_location( $attributes['__unstableLocation'] ) )
) {
$menu_items = gutenberg_get_menu_items_at_location( $attributes['__unstableLocation'] );
if ( empty( $menu_items ) ) {
return '';
Expand Down

0 comments on commit 9ac58ac

Please sign in to comment.