BlockAnchorSupportService.php
1 year ago
BlockPatternsService.php
1 year ago
BlockService.php
1 year ago
BlockServiceProvider.php
1 year ago
BlockStylesService.php
1 year ago
BlockValidationService.php
2 years ago
CartMenuIconMigrationService.php
1 year ago
CartMigrationService.php
1 year ago
FormModeSwitcherService.php
1 year ago
ProductCollectionBadgesMigrationService.php
1 year ago
ProductListMigrationService.php
1 year ago
ProductListService.php
1 year ago
ProductPageBlocksMigrationService.php
1 year ago
ProductPriceChoicesMigrationService.php
1 year ago
ProductSelectedPriceMigrationService.php
1 year ago
ProductVariantsMigrationService.php
1 year ago
URLParamService.php
1 year ago
ProductPageBlocksMigrationService.php
63 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\BlockLibrary; |
| 4 | |
| 5 | /** |
| 6 | * Provide the migration service for the product page blocks |
| 7 | */ |
| 8 | class ProductPageBlocksMigrationService { |
| 9 | /** |
| 10 | * Attributes |
| 11 | * |
| 12 | * @var array |
| 13 | */ |
| 14 | public array $attributes = array(); |
| 15 | |
| 16 | /** |
| 17 | * Block name. |
| 18 | * |
| 19 | * @var string |
| 20 | */ |
| 21 | public string $old_block_name = ''; |
| 22 | |
| 23 | /** |
| 24 | * Block. |
| 25 | * |
| 26 | * @var object |
| 27 | */ |
| 28 | public ?object $block = null; |
| 29 | |
| 30 | /** |
| 31 | * Constructor. |
| 32 | * |
| 33 | * @param object $block Block. |
| 34 | * @param string $old_block_name Old block name. |
| 35 | * |
| 36 | * @return void |
| 37 | */ |
| 38 | public function __construct( $block, $old_block_name ) { |
| 39 | $this->block = $block; |
| 40 | $this->old_block_name = $old_block_name; |
| 41 | $this->attributes = $block->parsed_block['attrs'] ?? []; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Maybe render old block. |
| 46 | * |
| 47 | * @param string $shortcode_name Short code name. |
| 48 | * |
| 49 | * @return string |
| 50 | */ |
| 51 | public function maybeRenderOldBlockFromShortCode( $shortcode_name ) { |
| 52 | if ( empty( $this->attributes['id'] ) ) { |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | // translators: %s: block name. |
| 57 | wp_trigger_error( '', sprintf( esc_html__( 'Passing an id to the [%s] shortcode is deprecated. Please use these shortcodes on product pages directly.', 'surecart' ), $shortcode_name ) ); |
| 58 | $block_content = '<!-- wp:' . $this->old_block_name . ' ' . wp_json_encode( $this->attributes ) . ' /-->'; |
| 59 | |
| 60 | return do_blocks( $block_content ); |
| 61 | } |
| 62 | } |
| 63 |