Changeset 56065 for trunk/src/wp-includes/blocks/navigation-submenu.php
- Timestamp:
- 06/27/2023 02:20:18 PM (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/navigation-submenu.php
r55475 r56065 15 15 * @return array Colors CSS classes and inline styles. 16 16 */ 17 function block_core_navigation_submenu_build_css_colors( $context, $attributes, $is_sub_menu = false ) {18 $colors = array(19 'css_classes' => array(),20 'inline_styles' => '',21 );22 23 // Text color.24 $named_text_color = null;25 $custom_text_color = null;26 27 if ( $is_sub_menu && array_key_exists( 'customOverlayTextColor', $context ) ) {28 $custom_text_color = $context['customOverlayTextColor'];29 } elseif ( $is_sub_menu && array_key_exists( 'overlayTextColor', $context ) ) {30 $named_text_color = $context['overlayTextColor'];31 } elseif ( array_key_exists( 'customTextColor', $context ) ) {32 $custom_text_color = $context['customTextColor'];33 } elseif ( array_key_exists( 'textColor', $context ) ) {34 $named_text_color = $context['textColor'];35 } elseif ( isset( $context['style']['color']['text'] ) ) {36 $custom_text_color = $context['style']['color']['text'];37 }38 39 // If has text color.40 if ( ! is_null( $named_text_color ) ) {41 // Add the color class.42 array_push( $colors['css_classes'], 'has-text-color', sprintf( 'has-%s-color', $named_text_color ) );43 } elseif ( ! is_null( $custom_text_color ) ) {44 // Add the custom color inline style.45 $colors['css_classes'][] = 'has-text-color';46 $colors['inline_styles'] .= sprintf( 'color: %s;', $custom_text_color );47 }48 49 // Background color.50 $named_background_color = null;51 $custom_background_color = null;52 53 if ( $is_sub_menu && array_key_exists( 'customOverlayBackgroundColor', $context ) ) {54 $custom_background_color = $context['customOverlayBackgroundColor'];55 } elseif ( $is_sub_menu && array_key_exists( 'overlayBackgroundColor', $context ) ) {56 $named_background_color = $context['overlayBackgroundColor'];57 } elseif ( array_key_exists( 'customBackgroundColor', $context ) ) {58 $custom_background_color = $context['customBackgroundColor'];59 } elseif ( array_key_exists( 'backgroundColor', $context ) ) {60 $named_background_color = $context['backgroundColor'];61 } elseif ( isset( $context['style']['color']['background'] ) ) {62 $custom_background_color = $context['style']['color']['background'];63 }64 65 // If has background color.66 if ( ! is_null( $named_background_color ) ) {67 // Add the background-color class.68 array_push( $colors['css_classes'], 'has-background', sprintf( 'has-%s-background-color', $named_background_color ) );69 } elseif ( ! is_null( $custom_background_color ) ) {70 // Add the custom background-color inline style.71 $colors['css_classes'][] = 'has-background';72 $colors['inline_styles'] .= sprintf( 'background-color: %s;', $custom_background_color );73 }74 75 return $colors;76 }77 17 78 18 /** … … 130 70 */ 131 71 function render_block_core_navigation_submenu( $attributes, $content, $block ) { 132 133 72 $navigation_link_has_id = isset( $attributes['id'] ) && is_numeric( $attributes['id'] ); 134 73 $is_post_type = isset( $attributes['kind'] ) && 'post-type' === $attributes['kind']; … … 145 84 } 146 85 147 $colors = block_core_navigation_submenu_build_css_colors( $block->context, $attributes );148 86 $font_sizes = block_core_navigation_submenu_build_css_font_sizes( $block->context ); 149 $classes = array_merge( 150 $colors['css_classes'], 151 $font_sizes['css_classes'] 152 ); 153 $style_attribute = ( $colors['inline_styles'] . $font_sizes['inline_styles'] ); 154 155 $css_classes = trim( implode( ' ', $classes ) ); 87 $style_attribute = $font_sizes['inline_styles']; 88 89 $css_classes = trim( implode( ' ', $font_sizes['css_classes'] ) ); 156 90 $has_submenu = count( $block->inner_blocks ) > 0; 157 $is_active = ! empty( $attributes['id'] ) && ( get_queried_object_id() === (int) $attributes['id'] ); 91 $kind = empty( $attributes['kind'] ) ? 'post_type' : str_replace( '-', '_', $attributes['kind'] ); 92 $is_active = ! empty( $attributes['id'] ) && get_queried_object_id() === (int) $attributes['id'] && ! empty( get_queried_object()->$kind ); 158 93 159 94 $show_submenu_indicators = isset( $block->context['showSubmenuIcon'] ) && $block->context['showSubmenuIcon']; … … 250 185 251 186 if ( $has_submenu ) { 252 $colors = block_core_navigation_submenu_build_css_colors( $block->context, $attributes, $has_submenu ); 253 $classes = array_merge( 254 array( 'wp-block-navigation__submenu-container' ), 255 $colors['css_classes'] 256 ); 257 $css_classes = trim( implode( ' ', $classes ) ); 258 259 $style_attribute = $colors['inline_styles']; 187 // Copy some attributes from the parent block to this one. 188 // Ideally this would happen in the client when the block is created. 189 if ( array_key_exists( 'overlayTextColor', $block->context ) ) { 190 $attributes['textColor'] = $block->context['overlayTextColor']; 191 } 192 if ( array_key_exists( 'overlayBackgroundColor', $block->context ) ) { 193 $attributes['backgroundColor'] = $block->context['overlayBackgroundColor']; 194 } 195 if ( array_key_exists( 'customOverlayTextColor', $block->context ) ) { 196 $attributes['style']['color']['text'] = $block->context['customOverlayTextColor']; 197 } 198 if ( array_key_exists( 'customOverlayBackgroundColor', $block->context ) ) { 199 $attributes['style']['color']['background'] = $block->context['customOverlayBackgroundColor']; 200 } 201 202 // This allows us to be able to get a response from gutenberg_apply_colors_support. 203 $block->block_type->supports['color'] = true; 204 $colors_supports = gutenberg_apply_colors_support( $block->block_type, $attributes ); 205 $css_classes = 'wp-block-navigation__submenu-container'; 206 if ( array_key_exists( 'class', $colors_supports ) ) { 207 $css_classes .= ' ' . $colors_supports['class']; 208 } 209 210 $style_attribute = ''; 211 if ( array_key_exists( 'style', $colors_supports ) ) { 212 $style_attribute = $colors_supports['style']; 213 } 260 214 261 215 $inner_blocks_html = '';
Note: See TracChangeset
for help on using the changeset viewer.