Changeset 53157 for trunk/src/wp-includes/blocks/navigation.php
- Timestamp:
- 04/12/2022 03:10:30 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/navigation.php
r52402 r53157 246 246 */ 247 247 function block_core_navigation_render_submenu_icon() { 248 return '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" role="img"aria-hidden="true" focusable="false"><path d="M1.50002 4L6.00002 8L10.5 4" stroke-width="1.5"></path></svg>';248 return '<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>'; 249 249 } 250 250 … … 344 344 * children of the `core/navigation` block. 345 345 * 346 * @since 5.9.0 347 * 346 348 * @param array[] default fallback blocks provided by the default block mechanic. 347 349 */ … … 352 354 * Renders the `core/navigation` block on server. 353 355 * 354 * @param array $attributes The block attributes.355 * @param array $contentThe saved content.356 * @param array $blockThe parsed block.356 * @param array $attributes The block attributes. 357 * @param string $content The saved content. 358 * @param WP_Block $block The parsed block. 357 359 * 358 360 * @return string Returns the post content with the legacy widget added. 359 361 */ 360 362 function render_block_core_navigation( $attributes, $content, $block ) { 363 364 static $seen_menu_names = array(); 361 365 362 366 // Flag used to indicate whether the rendered output is considered to be 363 367 // a fallback (i.e. the block has no menu associated with it). 364 368 $is_fallback = false; 369 370 $nav_menu_name = ''; 365 371 366 372 /** … … 427 433 } 428 434 435 $nav_menu_name = $navigation_post->post_title; 436 437 if ( isset( $seen_menu_names[ $nav_menu_name ] ) ) { 438 ++$seen_menu_names[ $nav_menu_name ]; 439 } else { 440 $seen_menu_names[ $nav_menu_name ] = 1; 441 } 442 429 443 $parsed_blocks = parse_blocks( $navigation_post->post_content ); 430 444 … … 472 486 $layout_class .= ' no-wrap'; 473 487 } 488 489 // Manually add block support text decoration as CSS class. 490 $text_decoration = _wp_array_get( $attributes, array( 'style', 'typography', 'textDecoration' ), null ); 491 $text_decoration_class = sprintf( 'has-text-decoration-%s', $text_decoration ); 474 492 475 493 $colors = block_core_navigation_build_css_colors( $attributes ); … … 480 498 $is_responsive_menu ? array( 'is-responsive' ) : array(), 481 499 $layout_class ? array( $layout_class ) : array(), 482 $is_fallback ? array( 'is-fallback' ) : array() 500 $is_fallback ? array( 'is-fallback' ) : array(), 501 $text_decoration ? array( $text_decoration_class ) : array() 483 502 ); 484 503 … … 507 526 $block_styles = isset( $attributes['styles'] ) ? $attributes['styles'] : ''; 508 527 528 // If the menu name has been used previously then append an ID 529 // to the name to ensure uniqueness across a given post. 530 if ( isset( $seen_menu_names[ $nav_menu_name ] ) && $seen_menu_names[ $nav_menu_name ] > 1 ) { 531 $count = $seen_menu_names[ $nav_menu_name ]; 532 $nav_menu_name = $nav_menu_name . ' ' . ( $count ); 533 } 534 509 535 $wrapper_attributes = get_block_wrapper_attributes( 510 536 array( 511 'class' => implode( ' ', $classes ), 512 'style' => $block_styles . $colors['inline_styles'] . $font_sizes['inline_styles'], 537 'class' => implode( ' ', $classes ), 538 'style' => $block_styles . $colors['inline_styles'] . $font_sizes['inline_styles'], 539 'aria-label' => $nav_menu_name, 513 540 ) 514 541 ); 515 542 516 $modal_unique_id = uniqid();543 $modal_unique_id = wp_unique_id( 'modal-' ); 517 544 518 545 // Determine whether or not navigation elements should be wrapped in the markup required to make it responsive, … … 538 565 ); 539 566 567 $toggle_button_icon = '<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><rect x="4" y="7.5" width="16" height="1.5" /><rect x="4" y="15" width="16" height="1.5" /></svg>'; 568 $should_display_icon_label = isset( $attributes['hasIcon'] ) && true === $attributes['hasIcon']; 569 $toggle_button_content = $should_display_icon_label ? $toggle_button_icon : 'Menu'; 570 540 571 $responsive_container_markup = sprintf( 541 '<button aria-haspopup="true" aria-label="%3$s" class="%6$s" data-micromodal-trigger=" modal-%1$s"><svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" role="img" aria-hidden="true" focusable="false"><rect x="4" y="7.5" width="16" height="1.5" /><rect x="4" y="15" width="16" height="1.5" /></svg></button>542 <div class="%5$s" style="%7$s" id=" modal-%1$s">572 '<button aria-haspopup="true" aria-label="%3$s" class="%6$s" data-micromodal-trigger="%1$s">%9$s</button> 573 <div class="%5$s" style="%7$s" id="%1$s"> 543 574 <div class="wp-block-navigation__responsive-close" tabindex="-1" data-micromodal-close> 544 575 <div class="wp-block-navigation__responsive-dialog" aria-label="%8$s"> 545 <button aria-label="%4$s" data-micromodal-close class="wp-block-navigation__responsive-container-close"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" role="img"aria-hidden="true" focusable="false"><path d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"></path></svg></button>546 <div class="wp-block-navigation__responsive-container-content" id=" modal-%1$s-content">576 <button aria-label="%4$s" data-micromodal-close class="wp-block-navigation__responsive-container-close"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"></path></svg></button> 577 <div class="wp-block-navigation__responsive-container-content" id="%1$s-content"> 547 578 %2$s 548 579 </div> … … 550 581 </div> 551 582 </div>', 552 $modal_unique_id,583 esc_attr( $modal_unique_id ), 553 584 $inner_blocks_html, 554 585 __( 'Open menu' ), // Open button label. 555 586 __( 'Close menu' ), // Close button label. 556 implode( ' ', $responsive_container_classes ), 557 implode( ' ', $open_button_classes ), 558 $colors['overlay_inline_styles'], 559 __( 'Menu' ) 587 esc_attr( implode( ' ', $responsive_container_classes ) ), 588 esc_attr( implode( ' ', $open_button_classes ) ), 589 safecss_filter_attr( $colors['overlay_inline_styles'] ), 590 __( 'Menu' ), 591 $toggle_button_content 560 592 ); 561 593 … … 570 602 * Register the navigation block. 571 603 * 604 * @uses render_block_core_navigation() 572 605 * @throws WP_Error An WP_Error exception parsing the block definition. 573 * @uses render_block_core_navigation()574 606 */ 575 607 function register_block_core_navigation() {
Note: See TracChangeset
for help on using the changeset viewer.