Skip to content

Commit

Permalink
Do not render if no fallback can be found for the Nav block (#36849)
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave authored and noisysocks committed Nov 29, 2021
1 parent 41e150b commit 8b95760
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/block-library/src/navigation/index.php
Expand Up @@ -187,14 +187,20 @@ function( $block ) {
* @return array the array of blocks to be used as a fallback.
*/
function block_core_navigation_get_fallback_blocks() {
// Default to a list of Pages.
$fallback_blocks = array(
$page_list_fallback = array(
array(
'blockName' => 'core/page-list',
'attrs' => array(),
),
);

$registry = WP_Block_Type_Registry::get_instance();

// If `core/page-list` is not registered then return empty blocks.
$fallback_blocks = $registry->is_registered( 'core/page-list' ) ? $page_list_fallback : array();

// Default to a list of Pages.

$navigation_post = block_core_navigation_get_first_non_empty_navigation();

// Prefer using the first non-empty Navigation as fallback if available.
Expand Down Expand Up @@ -298,6 +304,11 @@ function render_block_core_navigation( $attributes, $content, $block ) {

$fallback_blocks = block_core_navigation_get_fallback_blocks();

// May be empty if core/navigation or core/page list are not registered.
if ( empty( $fallback_blocks ) ) {
return '';
}

$inner_blocks = new WP_Block_List( $fallback_blocks, $attributes );
}

Expand Down

0 comments on commit 8b95760

Please sign in to comment.