Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
19 / 19 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
||
| 1 | <?php |
| 2 | /** |
| 3 | * No Results Variant block render. |
| 4 | * |
| 5 | * One empty-state condition inside a `jetpack-search/no-results` container. |
| 6 | * The author fills it with any blocks; this renderer emits them behind the |
| 7 | * store getter for the condition, and falls back to the localized default copy |
| 8 | * while the variant is still empty. |
| 9 | * |
| 10 | * @package automattic/jetpack-search |
| 11 | */ |
| 12 | |
| 13 | namespace Automattic\Jetpack\Search; |
| 14 | |
| 15 | // phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable |
| 16 | |
| 17 | // @phan-suppress-next-line PhanUndeclaredGlobalVariable |
| 18 | $condition = No_Results::normalize_condition( ( (array) $attributes )['condition'] ?? '' ); |
| 19 | |
| 20 | No_Results::seed_coverage( $condition ); |
| 21 | |
| 22 | // @phan-suppress-next-line PhanUndeclaredGlobalVariable -- $content is provided by WP at block render. |
| 23 | $authored_content = trim( $content ); |
| 24 | $is_default = '' === $authored_content; |
| 25 | $wrapper_class = 'jetpack-search-no-results__variant'; |
| 26 | if ( $is_default ) { |
| 27 | $wrapper_class .= ' jetpack-search-no-results--default'; |
| 28 | } |
| 29 | ?> |
| 30 | <div |
| 31 | <?php echo wp_kses_data( get_block_wrapper_attributes( array( 'class' => $wrapper_class ) ) ); ?> |
| 32 | data-wp-interactive="jetpack-search" |
| 33 | data-wp-bind--hidden="!<?php echo esc_attr( No_Results::visibility_getter( $condition ) ); ?>" |
| 34 | <?php echo wp_kses_data( No_Results::live_region_attribute( $condition ) ); ?> |
| 35 | hidden |
| 36 | > |
| 37 | <?php |
| 38 | if ( $is_default ) { |
| 39 | No_Results::render_default_copy( $condition ); |
| 40 | } else { |
| 41 | // @phan-suppress-next-line PhanUndeclaredGlobalVariable -- $content is provided by WP at block render. |
| 42 | echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Inner block HTML is already escaped by each child block's renderer. |
| 43 | } |
| 44 | ?> |
| 45 | </div> |