diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index 35d180509ec511..8c5aa720b488b5 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -413,15 +413,15 @@ function( $block ) { /** * Returns true if the navigation block contains a nested navigation block. * - * @param array $parsed_blocks the parsed blocks to be normalized. + * @param WP_Block_List $inner_blocks Inner block instance to be normalized. * @return bool true if the navigation block contains a nested navigation block. */ -function block_core_navigation_block_contains_core_navigation( $parsed_blocks ) { - foreach ( $parsed_blocks as $block ) { - if ( 'core/navigation' === $block['blockName'] ) { +function block_core_navigation_block_contains_core_navigation( $inner_blocks ) { + foreach ( $inner_blocks as $block ) { + if ( 'core/navigation' === $block->name ) { return true; } - if ( block_core_navigation_block_contains_core_navigation( $block['innerBlocks'] ) ) { + if ( $block->inner_blocks && block_core_navigation_block_contains_core_navigation( $block->inner_blocks ) ) { return true; } } @@ -643,8 +643,7 @@ function render_block_core_navigation( $attributes, $content, $block ) { $inner_blocks = new WP_Block_List( $fallback_blocks, $attributes ); } - $parsed_blocks = parse_blocks( $navigation_post->post_content ); - if ( block_core_navigation_block_contains_core_navigation( $parsed_blocks ) ) { + if ( block_core_navigation_block_contains_core_navigation( $inner_blocks ) ) { return ''; } diff --git a/phpunit/blocks/render-block-navigation-test.php b/phpunit/blocks/render-block-navigation-test.php index 7ba89d20de4183..211a20be3b9942 100644 --- a/phpunit/blocks/render-block-navigation-test.php +++ b/phpunit/blocks/render-block-navigation-test.php @@ -70,17 +70,20 @@ public function test_block_core_navigation_get_post_ids_from_block_with_submenu( */ public function test_gutenberg_block_core_navigation_block_contains_core_navigation() { $parsed_blocks = parse_blocks( '' ); - $this->assertTrue( gutenberg_block_core_navigation_block_contains_core_navigation( $parsed_blocks ) ); + $inner_blocks = new WP_Block_List( $parsed_blocks ); + $this->assertTrue( gutenberg_block_core_navigation_block_contains_core_navigation( $inner_blocks ) ); } public function test_gutenberg_block_core_navigation_block_contains_core_navigation_deep() { $parsed_blocks = parse_blocks( '' ); - $this->assertTrue( gutenberg_block_core_navigation_block_contains_core_navigation( $parsed_blocks ) ); + $inner_blocks = new WP_Block_List( $parsed_blocks ); + $this->assertTrue( gutenberg_block_core_navigation_block_contains_core_navigation( $inner_blocks ) ); } public function test_gutenberg_block_core_navigation_block_contains_core_navigation_no_navigation() { $parsed_blocks = parse_blocks( '' ); - $this->assertFalse( gutenberg_block_core_navigation_block_contains_core_navigation( $parsed_blocks ) ); + $inner_blocks = new WP_Block_List( $parsed_blocks ); + $this->assertFalse( gutenberg_block_core_navigation_block_contains_core_navigation( $inner_blocks ) ); } }