PluginProbe
Gutenberg / 22.7.0
Gutenberg v22.7.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 12.6.0 All 403 releases
← All changes | build/scripts/block-library/navigation-submenu.php +59 -37 23.6.2 → 22.7.0 View file →
@@ -4,25 +4,9 @@
4 4 *
5 5 * @package WordPress
6 6 */
7 7
8 -require_once __DIR__ . '/navigation-link/shared/item-should-render.php';
9 -require_once __DIR__ . '/navigation-link/shared/render-submenu-icon.php';
10 -
11 8 /**
12 - * Renders the submenu icon SVG for the Navigation Submenu block.
13 - *
14 - * @since 5.9.0
15 - * @deprecated 7.0.0 Use block_core_shared_navigation_render_submenu_icon() instead.
16 - *
17 - * @return string SVG markup for the submenu icon.
18 - */
19 -function gutenberg_block_core_navigation_submenu_render_submenu_icon() {
20 - _deprecated_function( __FUNCTION__, '7.0.0', 'block_core_shared_navigation_render_submenu_icon()' );
21 - return block_core_shared_navigation_render_submenu_icon();
22 -}
23 -
24 -/**
25 9 * Returns the submenu visibility value with backward compatibility
26 10 * for the deprecated openSubmenusOnClick attribute.
27 11 *
28 12 * This function centralizes the migration logic from the boolean
@@ -61,9 +45,55 @@
61 45 // Use submenuVisibility for migrated/new blocks.
62 46 return $submenu_visibility ?? 'hover';
63 47 }
64 48
49 +// Path differs between source and build: '../navigation-link/shared/' in source, './navigation-link/shared/' in build.
50 +if ( file_exists( __DIR__ . '/../navigation-link/shared/item-should-render.php' ) ) {
51 + require_once __DIR__ . '/../navigation-link/shared/item-should-render.php';
52 + require_once __DIR__ . '/../navigation-link/shared/render-submenu-icon.php';
53 +} else {
54 + require_once __DIR__ . '/navigation-link/shared/item-should-render.php';
55 + require_once __DIR__ . '/navigation-link/shared/render-submenu-icon.php';
56 +}
57 +
65 58 /**
59 + * Build an array with CSS classes and inline styles defining the font sizes
60 + * which will be applied to the navigation markup in the front-end.
61 + *
62 + * @since 5.9.0
63 + *
64 + * @param array $context Navigation block context.
65 + * @return array Font size CSS classes and inline styles.
66 + */
67 +function gutenberg_block_core_navigation_submenu_build_css_font_sizes( $context ) {
68 + // CSS classes.
69 + $font_sizes = array(
70 + 'css_classes' => array(),
71 + 'inline_styles' => '',
72 + );
73 +
74 + $has_named_font_size = array_key_exists( 'fontSize', $context );
75 + $has_custom_font_size = isset( $context['style']['typography']['fontSize'] );
76 +
77 + if ( $has_named_font_size ) {
78 + // Add the font size class.
79 + $font_sizes['css_classes'][] = sprintf( 'has-%s-font-size', $context['fontSize'] );
80 + } elseif ( $has_custom_font_size ) {
81 + // Add the custom font size inline style.
82 + $font_sizes['inline_styles'] = sprintf(
83 + 'font-size: %s;',
84 + gutenberg_get_typography_font_size_value(
85 + array(
86 + 'size' => $context['style']['typography']['fontSize'],
87 + )
88 + )
89 + );
90 + }
91 +
92 + return $font_sizes;
93 +}
94 +
95 +/**
66 96 * Renders the `core/navigation-submenu` block.
67 97 *
68 98 * @since 5.9.0
69 99 *
@@ -75,15 +105,12 @@
75 105 */
76 106 function gutenberg_render_block_core_navigation_submenu( $attributes, $content, $block ) {
77 107 // Check if this navigation item should render based on post status.
78 108 if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
79 - $should_render = gutenberg_block_core_shared_navigation_item_should_render( $attributes, $block );
80 - } else {
81 - $should_render = block_core_shared_navigation_item_should_render( $attributes, $block );
109 + if ( ! gutenberg_block_core_shared_navigation_item_should_render( $attributes, $block ) ) {
110 + return '';
111 + }
82 112 }
83 - if ( ! $should_render ) {
84 - return '';
85 - }
86 113
87 114 // Don't render the block's subtree if it has no label.
88 115 if ( empty( $attributes['label'] ) ) {
89 116 return '';
@@ -88,8 +115,11 @@
88 115 if ( empty( $attributes['label'] ) ) {
89 116 return '';
90 117 }
91 118
119 + $font_sizes = gutenberg_block_core_navigation_submenu_build_css_font_sizes( $block->context );
120 + $style_attribute = $font_sizes['inline_styles'];
121 +
92 122 // Render inner blocks first to check if any menu items will actually display.
93 123 $inner_blocks_html = '';
94 124 foreach ( $block->inner_blocks as $inner_block ) {
95 125 $inner_blocks_html .= $inner_block->render();
@@ -114,9 +144,12 @@
114 144
115 145 $classes = array(
116 146 'wp-block-navigation-item',
117 147 );
118 -
148 + $classes = array_merge(
149 + $classes,
150 + $font_sizes['css_classes']
151 + );
119 152 if ( $has_submenu ) {
120 153 $classes[] = 'has-child';
121 154 }
122 155 if ( $open_on_click ) {
@@ -134,8 +167,9 @@
134 167
135 168 $wrapper_attributes = get_block_wrapper_attributes(
136 169 array(
137 170 'class' => implode( ' ', $classes ),
171 + 'style' => $style_attribute,
138 172 )
139 173 );
140 174
141 175 $label = '';
@@ -205,15 +239,9 @@
205 239
206 240 if ( $show_submenu_indicators && $has_submenu ) {
207 241 // The submenu icon is rendered in a button here
208 242 // so that there's a clickable element to open the submenu.
209 - $html .= '<button aria-label="' . esc_attr( $aria_label ) . '" class="wp-block-navigation__submenu-icon wp-block-navigation-submenu__toggle" aria-expanded="false">';
210 - if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
211 - $html .= gutenberg_block_core_shared_navigation_render_submenu_icon();
212 - } else {
213 - $html .= block_core_shared_navigation_render_submenu_icon();
214 - }
215 - $html .= '</button>';
243 + $html .= '<button aria-label="' . esc_attr( $aria_label ) . '" class="wp-block-navigation__submenu-icon wp-block-navigation-submenu__toggle" aria-expanded="false">' . block_core_navigation_render_submenu_icon() . '</button>';
216 244 }
217 245 } else {
218 246 $html .= '<button aria-label="' . esc_attr( $aria_label ) . '" class="wp-block-navigation-item__content wp-block-navigation-submenu__toggle" aria-expanded="false">';
219 247
@@ -233,15 +261,9 @@
233 261
234 262 $html .= '</button>';
235 263
236 264 if ( $has_submenu ) {
237 - $html .= '<span class="wp-block-navigation__submenu-icon">';
238 - if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
239 - $html .= gutenberg_block_core_shared_navigation_render_submenu_icon();
240 - } else {
241 - $html .= block_core_shared_navigation_render_submenu_icon();
242 - }
243 - $html .= '</span>';
265 + $html .= '<span class="wp-block-navigation__submenu-icon">' . block_core_navigation_render_submenu_icon() . '</span>';
244 266 }
245 267 }
246 268
247 269 if ( $has_submenu ) {