block.json
3 months ago
bundle.php
1 week ago
controller.php
1 month ago
index.asset.php
6 days ago
index.js
6 days ago
radio.php
1 month ago
select.php
1 month ago
style-index-rtl.css
1 month ago
style-index.css
1 month ago
view.php
3 months ago
radio.php
79 lines
| 1 | <?php |
| 2 | // The composed (page) layout saves an inner product-variant-pill block. |
| 3 | // The bundle component layout reuses this picker without composed inner blocks, |
| 4 | // so synthesize a default pill so the markup/JS stay identical in both scopes. |
| 5 | $has_saved_inner = ! empty( $block->parsed_block['innerBlocks'] ); |
| 6 | |
| 7 | $inner_blocks = $has_saved_inner |
| 8 | ? $block->parsed_block['innerBlocks'] |
| 9 | : array( |
| 10 | array( |
| 11 | 'blockName' => 'surecart/product-variant-pill', |
| 12 | 'attrs' => array(), |
| 13 | 'innerBlocks' => array(), |
| 14 | 'innerHTML' => '', |
| 15 | 'innerContent' => array(), |
| 16 | ), |
| 17 | ); |
| 18 | |
| 19 | $inner_content = $has_saved_inner |
| 20 | ? ( $block->parsed_block['innerContent'] ?? array( null ) ) |
| 21 | : array( null ); |
| 22 | |
| 23 | // Get highlight styles from the inner product-variant-pill block. |
| 24 | $pill_block = wp_get_first_block( $inner_blocks, 'surecart/product-variant-pill' ); |
| 25 | $pill_block_attrs = $pill_block['attrs'] ?? array(); |
| 26 | ?> |
| 27 | |
| 28 | <label class="sc-form-label"> |
| 29 | <?php echo wp_kses_post( $pill_group_label ?? $option->name ); ?> |
| 30 | </label> |
| 31 | |
| 32 | <div |
| 33 | <?php |
| 34 | echo wp_kses_data( |
| 35 | get_block_wrapper_attributes( |
| 36 | [ |
| 37 | 'class' => 'sc-pill-option__wrapper', |
| 38 | 'style' => sc_get_inline_styles( |
| 39 | array_filter( |
| 40 | [ |
| 41 | '--sc-pill-option-active-background-color' => $pill_block_attrs['highlight_background'] ?? '', |
| 42 | '--sc-pill-option-active-text-color' => $pill_block_attrs['highlight_text'] ?? '', |
| 43 | '--sc-pill-option-active-border-color' => $pill_block_attrs['highlight_border'] ?? '', |
| 44 | ] |
| 45 | ) |
| 46 | ), |
| 47 | ] |
| 48 | ) |
| 49 | ); |
| 50 | ?> |
| 51 | > |
| 52 | <?php |
| 53 | foreach ( $option->values as $value ) : |
| 54 | // Get an instance of the current Post Template block. |
| 55 | $block_instance = $block->parsed_block; |
| 56 | |
| 57 | // Set the block name to one that does not correspond to an existing registered block. |
| 58 | // This ensures that for the inner instances of the Post Template block, we do not render any block supports. |
| 59 | $block_instance['blockName'] = 'core/null'; |
| 60 | $block_instance['innerBlocks'] = $inner_blocks; |
| 61 | $block_instance['innerContent'] = $inner_content; |
| 62 | |
| 63 | $filter_block_context = static function ( $context ) use ( $value, $option ) { |
| 64 | $context['value'] = $value; |
| 65 | $context['name'] = $option->name; |
| 66 | return $context; |
| 67 | }; |
| 68 | |
| 69 | // Use an early priority to so that other 'render_block_context' filters have access to the values. |
| 70 | add_filter( 'render_block_context', $filter_block_context, 1 ); |
| 71 | // Render the inner blocks of the Post Template block with `dynamic` set to `false` to prevent calling |
| 72 | // `render_callback` and ensure that no wrapper markup is included. |
| 73 | $block_content = ( new WP_Block( $block_instance ) )->render( array( 'dynamic' => false ) ); |
| 74 | remove_filter( 'render_block_context', $filter_block_context, 1 ); |
| 75 | ?> |
| 76 | <?php echo $block_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 77 | <?php endforeach; ?> |
| 78 | </div> |
| 79 |