diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index dcb98180b2a2c..20ac4a673b3f9 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -411,21 +411,22 @@ function( $block ) { } /** - * Bail on rendering nested navigation blocks + * Returns true if the navigation block contains a nested navigation block. * * @param array $parsed_blocks the parsed blocks to be normalized. - * @return array the normalized parsed blocks. + * @return bool true if the navigation block contains a nested navigation block. */ function block_core_navigation_has_nested_core_navigation( $parsed_blocks ) { - $filtered = array_filter( - $parsed_blocks, - function( $block ) { - return $block['blockName'] === 'core/navigation'; + foreach ( $parsed_blocks as $block ) { + if ( 'core/navigation' === $block['blockName'] ) { + return true; } - ); + if ( block_core_navigation_has_nested_core_navigation( $block['innerBlocks'] ) ) { + return true; + } + } - // Reset keys. - return count( $filtered ) > 0; + return false; } /** diff --git a/phpunit/blocks/render-block-navigation-test.php b/phpunit/blocks/render-block-navigation-test.php index e2eab4b72ca31..ffe4bf974e298 100644 --- a/phpunit/blocks/render-block-navigation-test.php +++ b/phpunit/blocks/render-block-navigation-test.php @@ -65,5 +65,22 @@ public function test_block_core_navigation_get_post_ids_from_block_with_submenu( $this->assertSameSetsWithIndex( array( 755, 789 ), $post_ids ); } + /** + * @covers ::gutenberg_block_core_navigation_has_nested_core_navigation + */ + public function test_gutenberg_block_core_navigation_has_nested_core_navigation() { + $parsed_blocks = parse_blocks( '' ); + $this->assertTrue( gutenberg_block_core_navigation_has_nested_core_navigation( $parsed_blocks ) ); + } + + public function test_gutenberg_block_core_navigation_has_nested_core_navigation_deep() { + $parsed_blocks = parse_blocks( '' ); + $this->assertTrue( gutenberg_block_core_navigation_has_nested_core_navigation( $parsed_blocks ) ); + } + + public function test_gutenberg_block_core_navigation_has_nested_core_navigation_no_navigation() { + $parsed_blocks = parse_blocks( '' ); + $this->assertFalse( gutenberg_block_core_navigation_has_nested_core_navigation( $parsed_blocks ) ); + } }