Block.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCartBlocks\Blocks\ProductDonationAmounts; |
| 4 | |
| 5 | use SureCartBlocks\Blocks\BaseBlock; |
| 6 | use SureCartBlocks\Util\BlockStyleAttributes; |
| 7 | |
| 8 | /** |
| 9 | * Product Title Block |
| 10 | */ |
| 11 | class Block extends BaseBlock { |
| 12 | /** |
| 13 | * Render the block |
| 14 | * |
| 15 | * @param array $attributes Block attributes. |
| 16 | * @param string $content Post content. |
| 17 | * |
| 18 | * @return string |
| 19 | */ |
| 20 | public function render( $attributes, $content ) { |
| 21 | [ 'styles' => $styles ] = BlockStyleAttributes::getClassesAndStylesFromAttributes( $attributes, [ 'margin' ] ); |
| 22 | |
| 23 | $wrapper_attributes = get_block_wrapper_attributes( |
| 24 | [ |
| 25 | 'style' => implode( |
| 26 | ' ', |
| 27 | [ |
| 28 | 'border: none;', |
| 29 | esc_attr( $this->getVars( $attributes, '--sc-choice' ) ), |
| 30 | '--columns:' . intval( $attributes['columns'] ) . ';', |
| 31 | ! empty( $attributes['style']['spacing']['blockGap'] ) ? '--sc-choices-gap:' . $this->getSpacingPresetCssVar( $attributes['style']['spacing']['blockGap'] ) . ';' : '', |
| 32 | $styles, |
| 33 | ] |
| 34 | ), |
| 35 | ] |
| 36 | ); |
| 37 | |
| 38 | return wp_sprintf( |
| 39 | '<div %s> |
| 40 | <sc-choices label="%s" required="%s"> |
| 41 | %s |
| 42 | </sc-choices> |
| 43 | </div>', |
| 44 | $wrapper_attributes, |
| 45 | esc_attr( $attributes['label'] ), |
| 46 | $this->block->context['surecart/product-donation/required'] ? 'true' : 'false', |
| 47 | filter_block_content( $content ) |
| 48 | ); |
| 49 | } |
| 50 | } |
| 51 |