Block.php
42 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCartBlocks\Blocks\Product\Title; |
| 4 | |
| 5 | use SureCartBlocks\Blocks\Product\ProductBlock; |
| 6 | |
| 7 | /** |
| 8 | * Product Title Block |
| 9 | */ |
| 10 | class Block extends ProductBlock { |
| 11 | /** |
| 12 | * Render the block |
| 13 | * |
| 14 | * @param array $attributes Block attributes. |
| 15 | * @param string $content Post content. |
| 16 | * |
| 17 | * @return string |
| 18 | */ |
| 19 | public function render( $attributes, $content ) { |
| 20 | $product = $this->getProductAndSetInitialState( $attributes['id'] ?? '' ); |
| 21 | if ( empty( $product ) ) { |
| 22 | return ''; |
| 23 | } |
| 24 | |
| 25 | $attributes = get_block_wrapper_attributes( |
| 26 | [ |
| 27 | 'class' => esc_attr( $this->getClasses( $attributes ) . ' surecart-block product-title' ), |
| 28 | 'style' => esc_attr( $this->getStyles( $attributes ) ), |
| 29 | ] |
| 30 | ); |
| 31 | |
| 32 | return sprintf( |
| 33 | '<%1$s %2$s> |
| 34 | %3$s |
| 35 | </%1$s>', |
| 36 | 'h' . (int) ( $attributes['level'] ?? 1 ), |
| 37 | $attributes, |
| 38 | wp_kses_post( $product->name ?? '' ) |
| 39 | ); |
| 40 | } |
| 41 | } |
| 42 |