Skip to content

Commit

Permalink
PHP Tests: Update conditional rendering of wrapper attributes to fix …
Browse files Browse the repository at this point in the history
…failing test case
  • Loading branch information
yogeshbhutkar committed Jan 1, 2025
1 parent 7ff2e55 commit faf394e
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions packages/block-library/src/navigation-submenu/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,19 +244,13 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) {
$attributes['textColor'] = $block->context['textColor'];
} elseif ( array_key_exists( 'customTextColor', $block->context ) ) {
$attributes['style']['color']['text'] = $block->context['customTextColor'];
} else {
// If there's no color provided in the context, and nothing to inherit then fallback to defaults.
// This is necessary to ensure submenu parent block colors are not inherited by the container.
$attributes['textColor'] = 'contrast';
}
}
if ( ! isset( $attributes['backgroundColor'] ) && ! isset( $attributes['style']['color']['background'] ) ) {
if ( array_key_exists( 'backgroundColor', $block->context ) ) {
$attributes['backgroundColor'] = $block->context['backgroundColor'];
} elseif ( array_key_exists( 'customBackgroundColor', $block->context ) ) {
$attributes['style']['color']['background'] = $block->context['customBackgroundColor'];
} else {
$attributes['backgroundColor'] = 'base';
}
}

Expand Down Expand Up @@ -286,11 +280,13 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) {
$html = $tag_processor->get_updated_html();
}

$wrapper_attributes = sprintf(
'style="%1$s" class="%2$s"',
$style_attribute,
$css_classes
);
$wrapper_attributes = '';
if ( ! empty( $style_attribute ) ) {
$wrapper_attributes .= sprintf( 'style="%s"', $style_attribute );
}
if ( ! empty( $css_classes ) ) {
$wrapper_attributes .= sprintf( 'class="%s"', $css_classes );
}

$html .= sprintf(
'<ul %s>%s</ul>',
Expand Down

0 comments on commit faf394e

Please sign in to comment.