80 } |
80 } |
81 |
81 |
82 $font_sizes = block_core_navigation_submenu_build_css_font_sizes( $block->context ); |
82 $font_sizes = block_core_navigation_submenu_build_css_font_sizes( $block->context ); |
83 $style_attribute = $font_sizes['inline_styles']; |
83 $style_attribute = $font_sizes['inline_styles']; |
84 |
84 |
85 $css_classes = trim( implode( ' ', $font_sizes['css_classes'] ) ); |
|
86 $has_submenu = count( $block->inner_blocks ) > 0; |
85 $has_submenu = count( $block->inner_blocks ) > 0; |
87 $kind = empty( $attributes['kind'] ) ? 'post_type' : str_replace( '-', '_', $attributes['kind'] ); |
86 $kind = empty( $attributes['kind'] ) ? 'post_type' : str_replace( '-', '_', $attributes['kind'] ); |
88 $is_active = ! empty( $attributes['id'] ) && get_queried_object_id() === (int) $attributes['id'] && ! empty( get_queried_object()->$kind ); |
87 $is_active = ! empty( $attributes['id'] ) && get_queried_object_id() === (int) $attributes['id'] && ! empty( get_queried_object()->$kind ); |
89 |
88 |
90 if ( is_post_type_archive() ) { |
89 if ( is_post_type_archive() ) { |
97 $show_submenu_indicators = isset( $block->context['showSubmenuIcon'] ) && $block->context['showSubmenuIcon']; |
96 $show_submenu_indicators = isset( $block->context['showSubmenuIcon'] ) && $block->context['showSubmenuIcon']; |
98 $open_on_click = isset( $block->context['openSubmenusOnClick'] ) && $block->context['openSubmenusOnClick']; |
97 $open_on_click = isset( $block->context['openSubmenusOnClick'] ) && $block->context['openSubmenusOnClick']; |
99 $open_on_hover_and_click = isset( $block->context['openSubmenusOnClick'] ) && ! $block->context['openSubmenusOnClick'] && |
98 $open_on_hover_and_click = isset( $block->context['openSubmenusOnClick'] ) && ! $block->context['openSubmenusOnClick'] && |
100 $show_submenu_indicators; |
99 $show_submenu_indicators; |
101 |
100 |
|
101 $classes = array( |
|
102 'wp-block-navigation-item', |
|
103 ); |
|
104 $classes = array_merge( |
|
105 $classes, |
|
106 $font_sizes['css_classes'] |
|
107 ); |
|
108 if ( $has_submenu ) { |
|
109 $classes[] = 'has-child'; |
|
110 } |
|
111 if ( $open_on_click ) { |
|
112 $classes[] = 'open-on-click'; |
|
113 } |
|
114 if ( $open_on_hover_and_click ) { |
|
115 $classes[] = 'open-on-hover-click'; |
|
116 } |
|
117 if ( $is_active ) { |
|
118 $classes[] = 'current-menu-item'; |
|
119 } |
|
120 |
102 $wrapper_attributes = get_block_wrapper_attributes( |
121 $wrapper_attributes = get_block_wrapper_attributes( |
103 array( |
122 array( |
104 'class' => $css_classes . ' wp-block-navigation-item' . ( $has_submenu ? ' has-child' : '' ) . |
123 'class' => implode( ' ', $classes ), |
105 ( $open_on_click ? ' open-on-click' : '' ) . ( $open_on_hover_and_click ? ' open-on-hover-click' : '' ) . |
|
106 ( $is_active ? ' current-menu-item' : '' ), |
|
107 'style' => $style_attribute, |
124 'style' => $style_attribute, |
108 ) |
125 ) |
109 ); |
126 ); |
110 |
127 |
111 $label = ''; |
128 $label = ''; |
157 } |
174 } |
158 |
175 |
159 $html .= '>'; |
176 $html .= '>'; |
160 // End appending HTML attributes to anchor tag. |
177 // End appending HTML attributes to anchor tag. |
161 |
178 |
|
179 $html .= '<span class="wp-block-navigation-item__label">'; |
162 $html .= $label; |
180 $html .= $label; |
|
181 $html .= '</span>'; |
|
182 |
|
183 // Add description if available. |
|
184 if ( ! empty( $attributes['description'] ) ) { |
|
185 $html .= '<span class="wp-block-navigation-item__description">'; |
|
186 $html .= wp_kses_post( $attributes['description'] ); |
|
187 $html .= '</span>'; |
|
188 } |
163 |
189 |
164 $html .= '</a>'; |
190 $html .= '</a>'; |
165 // End anchor tag content. |
191 // End anchor tag content. |
166 |
192 |
167 if ( $show_submenu_indicators ) { |
193 if ( $show_submenu_indicators ) { |
177 $html .= '<span class="wp-block-navigation-item__label">'; |
203 $html .= '<span class="wp-block-navigation-item__label">'; |
178 |
204 |
179 $html .= $label; |
205 $html .= $label; |
180 |
206 |
181 $html .= '</span>'; |
207 $html .= '</span>'; |
|
208 |
|
209 // Add description if available. |
|
210 if ( ! empty( $attributes['description'] ) ) { |
|
211 $html .= '<span class="wp-block-navigation-item__description">'; |
|
212 $html .= wp_kses_post( $attributes['description'] ); |
|
213 $html .= '</span>'; |
|
214 } |
182 |
215 |
183 $html .= '</button>'; |
216 $html .= '</button>'; |
184 |
217 |
185 $html .= '<span class="wp-block-navigation__submenu-icon">' . block_core_navigation_submenu_render_submenu_icon() . '</span>'; |
218 $html .= '<span class="wp-block-navigation__submenu-icon">' . block_core_navigation_submenu_render_submenu_icon() . '</span>'; |
186 |
219 |
220 $inner_blocks_html .= $inner_block->render(); |
253 $inner_blocks_html .= $inner_block->render(); |
221 } |
254 } |
222 |
255 |
223 if ( strpos( $inner_blocks_html, 'current-menu-item' ) ) { |
256 if ( strpos( $inner_blocks_html, 'current-menu-item' ) ) { |
224 $tag_processor = new WP_HTML_Tag_Processor( $html ); |
257 $tag_processor = new WP_HTML_Tag_Processor( $html ); |
225 while ( $tag_processor->next_tag( array( 'class_name' => 'wp-block-navigation-item__content' ) ) ) { |
258 while ( $tag_processor->next_tag( array( 'class_name' => 'wp-block-navigation-item' ) ) ) { |
226 $tag_processor->add_class( 'current-menu-ancestor' ); |
259 $tag_processor->add_class( 'current-menu-ancestor' ); |
227 } |
260 } |
228 $html = $tag_processor->get_updated_html(); |
261 $html = $tag_processor->get_updated_html(); |
229 } |
262 } |
230 |
263 |