Changeset 55246 for trunk/src/wp-includes/blocks/page-list.php
- Timestamp:
- 02/07/2023 07:01:56 AM (3 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/blocks/page-list.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/page-list.php
r54486 r55246 140 140 * @param boolean $is_navigation_child If block is a child of Navigation block. 141 141 * @param array $nested_pages The array of nested pages. 142 * @param boolean $is_nested Whether the submenu is nested or not. 142 143 * @param array $active_page_ancestor_ids An array of ancestor ids for active page. 143 144 * @param array $colors Color information for overlay styles. … … 146 147 * @return string List markup. 147 148 */ 148 function block_core_page_list_render_nested_page_list( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $nested_pages, $ active_page_ancestor_ids = array(), $colors = array(), $depth = 0 ) {149 function block_core_page_list_render_nested_page_list( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $nested_pages, $is_nested, $active_page_ancestor_ids = array(), $colors = array(), $depth = 0 ) { 149 150 if ( empty( $nested_pages ) ) { 150 151 return; … … 174 175 175 176 // If this is the first level of submenus, include the overlay colors. 176 if ( 1 === $depth&& isset( $colors['overlay_css_classes'], $colors['overlay_inline_styles'] ) ) {177 if ( ( ( 0 < $depth && ! $is_nested ) || $is_nested ) && isset( $colors['overlay_css_classes'], $colors['overlay_inline_styles'] ) ) { 177 178 $css_class .= ' ' . trim( implode( ' ', $colors['overlay_css_classes'] ) ); 178 179 if ( '' !== $colors['overlay_inline_styles'] ) { … … 197 198 if ( isset( $page['children'] ) && $is_navigation_child && $open_submenus_on_click ) { 198 199 $markup .= '<button aria-label="' . esc_attr( $aria_label ) . '" class="' . esc_attr( $navigation_child_content_class ) . ' wp-block-navigation-submenu__toggle" aria-expanded="false">' . esc_html( $title ) . 199 '</button> ' . '<span class="wp-block-page-list__submenu-icon wp-block-navigation__submenu-icon"><svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true" focusable="false"><path d="M1.50002 4L6.00002 8L10.5 4" stroke-width="1.5"></path></svg></span>';200 '</button><span class="wp-block-page-list__submenu-icon wp-block-navigation__submenu-icon"><svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true" focusable="false"><path d="M1.50002 4L6.00002 8L10.5 4" stroke-width="1.5"></path></svg></span>'; 200 201 } else { 201 202 $markup .= '<a class="wp-block-pages-list__item__link' . esc_attr( $navigation_child_content_class ) . '" href="' . esc_url( $page['link'] ) . '"' . $aria_current . '>' . $title . '</a>'; … … 208 209 $markup .= '</button>'; 209 210 } 210 $markup .= '<ul class="submenu-container'; 211 // Extra classname is added when the block is a child of Navigation. 212 if ( $is_navigation_child ) { 213 $markup .= ' wp-block-navigation__submenu-container'; 214 } 215 $markup .= '">' . block_core_page_list_render_nested_page_list( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $page['children'], $active_page_ancestor_ids, $colors, $depth + 1 ) . '</ul>'; 211 $markup .= '<ul class="wp-block-navigation__submenu-container">'; 212 $markup .= block_core_page_list_render_nested_page_list( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $page['children'], $is_nested, $active_page_ancestor_ids, $colors, $depth + 1 ); 213 $markup .= '</ul>'; 216 214 } 217 215 $markup .= '</li>'; … … 251 249 function render_block_core_page_list( $attributes, $content, $block ) { 252 250 static $block_id = 0; 253 $block_id++; 251 ++$block_id; 252 253 $parent_page_id = $attributes['parentPageID']; 254 $is_nested = $attributes['isNested']; 254 255 255 256 $all_pages = get_pages( … … 272 273 273 274 foreach ( (array) $all_pages as $page ) { 274 $is_active = ! empty( $page->ID ) && ( get_ the_ID() === $page->ID );275 $is_active = ! empty( $page->ID ) && ( get_queried_object_id() === $page->ID ); 275 276 276 277 if ( $is_active ) { … … 307 308 $nested_pages = block_core_page_list_nest_pages( $top_level_pages, $pages_with_children ); 308 309 310 if ( 0 !== $parent_page_id ) { 311 // If the parent page has no child pages, there is nothing to show. 312 if ( ! array_key_exists( $parent_page_id, $pages_with_children ) ) { 313 return; 314 } 315 316 $nested_pages = block_core_page_list_nest_pages( 317 $pages_with_children[ $parent_page_id ], 318 $pages_with_children 319 ); 320 } 321 309 322 $is_navigation_child = array_key_exists( 'showSubmenuIcon', $block->context ); 310 323 … … 313 326 $show_submenu_icons = array_key_exists( 'showSubmenuIcon', $block->context ) ? $block->context['showSubmenuIcon'] : false; 314 327 315 $wrapper_markup = '<ul %1$s>%2$s</ul>';316 317 $items_markup = block_core_page_list_render_nested_page_list( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $nested_pages, $ active_page_ancestor_ids, $colors );328 $wrapper_markup = $is_nested ? '%2$s' : '<ul %1$s>%2$s</ul>'; 329 330 $items_markup = block_core_page_list_render_nested_page_list( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $nested_pages, $is_nested, $active_page_ancestor_ids, $colors ); 318 331 319 332 $wrapper_attributes = get_block_wrapper_attributes(
Note: See TracChangeset
for help on using the changeset viewer.