PluginProbe
Gutenberg / trunk
Gutenberg vtrunk
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
← All changes | build/scripts/block-library/navigation.php +48 -19 23.7.1 → trunk View file →
@@ -278,10 +278,16 @@
278 278 $is_list_open = false;
279 279
280 280 foreach ( $inner_blocks as $inner_block ) {
281 281 $inner_block_markup = static::get_markup_for_inner_block( $inner_block );
282 - $p = new WP_HTML_Tag_Processor( $inner_block_markup );
283 - $is_list_item = $p->next_tag( 'LI' );
282 + // Skip hidden blocks (e.g. hidden via block visibility) that render
283 + // as an empty string. Without this check, empty markup is mistaken
284 + // for a non-list-item and incorrectly closes the open <ul>.
285 + if ( '' === $inner_block_markup ) {
286 + continue;
287 + }
288 + $p = new WP_HTML_Tag_Processor( $inner_block_markup );
289 + $is_list_item = $p->next_tag( 'LI' );
284 290
285 291 if ( $is_list_item && ! $is_list_open ) {
286 292 $is_list_open = true;
287 293 $inner_blocks_html .= sprintf(
@@ -410,9 +416,9 @@
410 416 *
411 417 * @since 6.5.0
412 418 *
413 419 * @param string $overlay_template_part_id The overlay template part ID in format "theme//slug".
414 - * @param array $attributes The block attributes.
420 + * @param array $attributes The block attributes.
415 421 * @return WP_Block_List Returns the inner blocks for the overlay template part.
416 422 */
417 423 private static function get_overlay_blocks_from_template_part( $overlay_template_part_id, $attributes ) {
418 424 if ( empty( $overlay_template_part_id ) || ! is_string( $overlay_template_part_id ) ) {
@@ -511,9 +517,9 @@
511 517 *
512 518 * @since 6.5.0
513 519 *
514 520 * @param array $attributes The block attributes.
515 - * @param WP_Block $block The parsed block.
521 + * @param WP_Block $block The parsed block.
516 522 * @return WP_Block_List Returns the inner blocks for the navigation block.
517 523 */
518 524 private static function get_inner_blocks( $attributes, $block ) {
519 525 $inner_blocks = $block->inner_blocks;
@@ -682,11 +688,16 @@
682 688 *
683 689 * @since 7.0.0
684 690 *
685 691 * @param bool $is_hidden_by_default Whether the responsive menu is hidden by default.
686 - * @param bool $has_custom_overlay Whether a custom overlay is used.
687 - * @param array $colors The colors array.
692 + * @param bool $has_custom_overlay Whether a custom overlay is used.
693 + * @param array $colors The colors array.
688 694 * @return array Returns the responsive container classes.
695 + *
696 + * @phpstan-param array{
697 + * overlay_css_classes: list<string>,
698 + * ...
699 + * } $colors
689 700 */
690 701 private static function get_responsive_container_classes( $is_hidden_by_default, $has_custom_overlay, $colors ) {
691 702 $responsive_container_classes = array( 'wp-block-navigation__responsive-container' );
692 703
@@ -709,10 +720,16 @@
709 720 * Get overlay inline styles for the navigation block.
710 721 *
711 722 * @since 7.0.0
712 723 *
713 - * @param array $colors The colors array.
724 + * @param bool $has_custom_overlay Whether a custom overlay is used.
725 + * @param array $colors The colors array.
714 726 * @return string Returns the overlay inline styles.
727 + *
728 + * @phpstan-param array{
729 + * overlay_inline_styles: string,
730 + * ...
731 + * } $colors
715 732 */
716 733 private static function get_overlay_inline_styles( $has_custom_overlay, $colors ) {
717 734 $overlay_inline_styles = $has_custom_overlay ? '' : esc_attr( safecss_filter_attr( $colors['overlay_inline_styles'] ) );
718 735 return ( ! empty( $overlay_inline_styles ) ) ? "style=\"$overlay_inline_styles\"" : '';
@@ -722,10 +739,10 @@
722 739 * Get the responsive container markup
723 740 *
724 741 * @since 6.5.0
725 742 *
726 - * @param array $attributes The block attributes.
727 - * @param WP_Block_List $inner_blocks The list of inner blocks.
743 + * @param array $attributes The block attributes.
744 + * @param WP_Block_List $inner_blocks The list of inner blocks.
728 745 * @param string $inner_blocks_html The markup for the inner blocks.
729 746 * @return string Returns the container markup.
730 747 */
731 748 private static function get_responsive_container_markup( $attributes, $inner_blocks, $inner_blocks_html ) {
@@ -814,8 +831,16 @@
814 831 ';
815 832 $responsive_container_content_directives = '
816 833 data-wp-watch="callbacks.focusFirstElement"
817 834 ';
835 +
836 + // The default overlay displays every submenu it contains; a custom overlay
837 + // opts out through the `disable-default-overlay` class on this container.
838 + // Submenus inherit this flag to tell the two apart, derived from the same
839 + // value as that class so the markup and the styles cannot disagree.
840 + if ( $has_custom_overlay ) {
841 + $responsive_container_directives .= ' ' . wp_interactivity_data_wp_context( array( 'hasCustomOverlay' => true ) );
842 + }
818 843 }
819 844
820 845 // Don't apply overlay inline styles if using a custom overlay template part.
821 846 // The custom overlay is responsible for its own styling.
@@ -874,10 +899,10 @@
874 899 * Get the wrapper attributes
875 900 *
876 901 * @since 6.5.0
877 902 *
878 - * @param array $attributes The block attributes.
879 - * @param WP_Block_List $inner_blocks A list of inner blocks.
903 + * @param array $attributes The block attributes.
904 + * @param WP_Block_List $inner_blocks A list of inner blocks.
880 905 * @return string Returns the navigation block markup.
881 906 */
882 907 private static function get_nav_attributes( $attributes, $inner_blocks ) {
883 908 $is_interactive = static::is_interactive( $attributes, $inner_blocks );
@@ -961,9 +986,9 @@
961 986 * Returns the markup for the navigation block.
962 987 *
963 988 * @since 6.5.0
964 989 *
965 - * @param array $attributes The block attributes.
990 + * @param array $attributes The block attributes.
966 991 * @param WP_Block_List $inner_blocks The list of inner blocks.
967 992 * @return string Returns the navigation wrapper markup.
968 993 */
969 994 private static function get_inner_block_markup( $attributes, $inner_blocks ) {
@@ -1030,8 +1055,12 @@
1030 1055 }
1031 1056
1032 1057 unset( $attributes['rgbTextColor'], $attributes['rgbBackgroundColor'] );
1033 1058
1059 + // Submenu detection is memoized while a navigation block renders. Reset it so
1060 + // the result of a previously rendered navigation block is not reused for this one.
1061 + static::$has_submenus = false;
1062 +
1034 1063 $inner_blocks = static::get_inner_blocks( $attributes, $block );
1035 1064 // Prevent navigation blocks referencing themselves from rendering.
1036 1065 if ( gutenberg_block_core_navigation_block_tree_has_block_type(
1037 1066 $inner_blocks,
@@ -1768,14 +1797,14 @@
1768 1797 * @since 5.9.0
1769 1798 *
1770 1799 * @deprecated 6.3.0 Use WP_Navigation_Fallback::parse_blocks_from_menu_items() instead.
1771 1800 *
1772 - * @param array $menu_items An array of menu items that represent
1773 - * an individual level of a menu.
1774 - * @param array $menu_items_by_parent_id An array keyed by the id of the
1775 - * parent menu where each element is an
1776 - * array of menu items that belong to
1777 - * that parent.
1801 + * @param array $menu_items An array of menu items that represent
1802 + * an individual level of a menu.
1803 + * @param array $menu_items_by_parent_id An array keyed by the id of the
1804 + * parent menu where each element is an
1805 + * array of menu items that belong to
1806 + * that parent.
1778 1807 * @return array An array of parsed block data.
1779 1808 */
1780 1809 function gutenberg_block_core_navigation_parse_blocks_from_menu_items( $menu_items, $menu_items_by_parent_id ) {
1781 1810
@@ -1873,9 +1902,9 @@
1873 1902 * @since 6.2.0
1874 1903 *
1875 1904 * @deprecated 6.3.0 Use WP_Navigation_Fallback::get_classic_menu_fallback_blocks() instead.
1876 1905 *
1877 - * @param object $classic_nav_menu WP_Term The classic navigation object to convert.
1906 + * @param object $classic_nav_menu WP_Term The classic navigation object to convert.
1878 1907 * @return array the normalized parsed blocks.
1879 1908 */
1880 1909 function gutenberg_block_core_navigation_get_classic_menu_fallback_blocks( $classic_nav_menu ) {
1881 1910