@@ -6,49 +6,49 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | class ProductStockIndicator extends AbstractBlock { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * Block name. |
|
| 11 | - * |
|
| 12 | - * @var string |
|
| 13 | - */ |
|
| 14 | - protected $block_name = 'product-stock-indicator'; |
|
| 9 | + /** |
|
| 10 | + * Block name. |
|
| 11 | + * |
|
| 12 | + * @var string |
|
| 13 | + */ |
|
| 14 | + protected $block_name = 'product-stock-indicator'; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * API version name. |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - protected $api_version = '2'; |
|
| 16 | + /** |
|
| 17 | + * API version name. |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + protected $api_version = '2'; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Get block supports. Shared with the frontend. |
|
| 25 | - * IMPORTANT: If you change anything here, make sure to update the JS file too. |
|
| 26 | - * |
|
| 27 | - * @return array |
|
| 28 | - */ |
|
| 29 | - protected function get_block_type_supports() { |
|
| 30 | - return array( |
|
| 31 | - 'color' => |
|
| 32 | - array( |
|
| 33 | - 'link' => false, |
|
| 34 | - 'background' => false, |
|
| 35 | - 'text' => true, |
|
| 36 | - ), |
|
| 37 | - 'typography' => |
|
| 38 | - array( |
|
| 39 | - 'fontSize' => true, |
|
| 40 | - ), |
|
| 41 | - '__experimentalSelector' => '.wc-block-components-product-stock-indicator', |
|
| 42 | - ); |
|
| 43 | - } |
|
| 23 | + /** |
|
| 24 | + * Get block supports. Shared with the frontend. |
|
| 25 | + * IMPORTANT: If you change anything here, make sure to update the JS file too. |
|
| 26 | + * |
|
| 27 | + * @return array |
|
| 28 | + */ |
|
| 29 | + protected function get_block_type_supports() { |
|
| 30 | + return array( |
|
| 31 | + 'color' => |
|
| 32 | + array( |
|
| 33 | + 'link' => false, |
|
| 34 | + 'background' => false, |
|
| 35 | + 'text' => true, |
|
| 36 | + ), |
|
| 37 | + 'typography' => |
|
| 38 | + array( |
|
| 39 | + 'fontSize' => true, |
|
| 40 | + ), |
|
| 41 | + '__experimentalSelector' => '.wc-block-components-product-stock-indicator', |
|
| 42 | + ); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Register script and style assets for the block type before it is registered. |
|
| 47 | - * |
|
| 48 | - * This registers the scripts; it does not enqueue them. |
|
| 49 | - */ |
|
| 50 | - protected function register_block_type_assets() { |
|
| 51 | - parent::register_block_type_assets(); |
|
| 52 | - $this->register_chunk_translations( [ $this->block_name ] ); |
|
| 53 | - } |
|
| 45 | + /** |
|
| 46 | + * Register script and style assets for the block type before it is registered. |
|
| 47 | + * |
|
| 48 | + * This registers the scripts; it does not enqueue them. |
|
| 49 | + */ |
|
| 50 | + protected function register_block_type_assets() { |
|
| 51 | + parent::register_block_type_assets(); |
|
| 52 | + $this->register_chunk_translations( [ $this->block_name ] ); |
|
| 53 | + } |
|
| 54 | 54 | } |
@@ -51,6 +51,6 @@ |
||
| 51 | 51 | */ |
| 52 | 52 | protected function register_block_type_assets() { |
| 53 | 53 | parent::register_block_type_assets(); |
| 54 | - $this->register_chunk_translations( [ $this->block_name ] ); |
|
| 54 | + $this->register_chunk_translations([$this->block_name]); |
|
| 55 | 55 | } |
| 56 | 56 | } |
@@ -5,38 +5,38 @@ |
||
| 5 | 5 | * AllProducts class. |
| 6 | 6 | */ |
| 7 | 7 | class AllProducts extends AbstractBlock { |
| 8 | - /** |
|
| 9 | - * Block name. |
|
| 10 | - * |
|
| 11 | - * @var string |
|
| 12 | - */ |
|
| 13 | - protected $block_name = 'all-products'; |
|
| 8 | + /** |
|
| 9 | + * Block name. |
|
| 10 | + * |
|
| 11 | + * @var string |
|
| 12 | + */ |
|
| 13 | + protected $block_name = 'all-products'; |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Extra data passed through from server to client for block. |
|
| 17 | - * |
|
| 18 | - * @param array $attributes Any attributes that currently are available from the block. |
|
| 19 | - * Note, this will be empty in the editor context when the block is |
|
| 20 | - * not in the post content on editor load. |
|
| 21 | - */ |
|
| 22 | - protected function enqueue_data( array $attributes = [] ) { |
|
| 23 | - parent::enqueue_data( $attributes ); |
|
| 24 | - // Set this so filter blocks being used as widgets know when to render. |
|
| 25 | - $this->asset_data_registry->add( 'has_filterable_products', true, true ); |
|
| 15 | + /** |
|
| 16 | + * Extra data passed through from server to client for block. |
|
| 17 | + * |
|
| 18 | + * @param array $attributes Any attributes that currently are available from the block. |
|
| 19 | + * Note, this will be empty in the editor context when the block is |
|
| 20 | + * not in the post content on editor load. |
|
| 21 | + */ |
|
| 22 | + protected function enqueue_data( array $attributes = [] ) { |
|
| 23 | + parent::enqueue_data( $attributes ); |
|
| 24 | + // Set this so filter blocks being used as widgets know when to render. |
|
| 25 | + $this->asset_data_registry->add( 'has_filterable_products', true, true ); |
|
| 26 | 26 | |
| 27 | - $this->asset_data_registry->add( 'min_columns', wc_get_theme_support( 'product_blocks::min_columns', 1 ), true ); |
|
| 28 | - $this->asset_data_registry->add( 'max_columns', wc_get_theme_support( 'product_blocks::max_columns', 6 ), true ); |
|
| 29 | - $this->asset_data_registry->add( 'default_columns', wc_get_theme_support( 'product_blocks::default_columns', 3 ), true ); |
|
| 30 | - $this->asset_data_registry->add( 'min_rows', wc_get_theme_support( 'product_blocks::min_rows', 1 ), true ); |
|
| 31 | - $this->asset_data_registry->add( 'max_rows', wc_get_theme_support( 'product_blocks::max_rows', 6 ), true ); |
|
| 32 | - $this->asset_data_registry->add( 'default_rows', wc_get_theme_support( 'product_blocks::default_rows', 3 ), true ); |
|
| 33 | - $this->hydrate_from_api(); |
|
| 34 | - } |
|
| 27 | + $this->asset_data_registry->add( 'min_columns', wc_get_theme_support( 'product_blocks::min_columns', 1 ), true ); |
|
| 28 | + $this->asset_data_registry->add( 'max_columns', wc_get_theme_support( 'product_blocks::max_columns', 6 ), true ); |
|
| 29 | + $this->asset_data_registry->add( 'default_columns', wc_get_theme_support( 'product_blocks::default_columns', 3 ), true ); |
|
| 30 | + $this->asset_data_registry->add( 'min_rows', wc_get_theme_support( 'product_blocks::min_rows', 1 ), true ); |
|
| 31 | + $this->asset_data_registry->add( 'max_rows', wc_get_theme_support( 'product_blocks::max_rows', 6 ), true ); |
|
| 32 | + $this->asset_data_registry->add( 'default_rows', wc_get_theme_support( 'product_blocks::default_rows', 3 ), true ); |
|
| 33 | + $this->hydrate_from_api(); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Hydrate the All Product block with data from the API. |
|
| 38 | - */ |
|
| 39 | - protected function hydrate_from_api() { |
|
| 40 | - $this->asset_data_registry->hydrate_api_request( '/wc/store/v1/cart' ); |
|
| 41 | - } |
|
| 36 | + /** |
|
| 37 | + * Hydrate the All Product block with data from the API. |
|
| 38 | + */ |
|
| 39 | + protected function hydrate_from_api() { |
|
| 40 | + $this->asset_data_registry->hydrate_api_request( '/wc/store/v1/cart' ); |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -19,17 +19,17 @@ discard block |
||
| 19 | 19 | * Note, this will be empty in the editor context when the block is |
| 20 | 20 | * not in the post content on editor load. |
| 21 | 21 | */ |
| 22 | - protected function enqueue_data( array $attributes = [] ) { |
|
| 23 | - parent::enqueue_data( $attributes ); |
|
| 22 | + protected function enqueue_data(array $attributes = []) { |
|
| 23 | + parent::enqueue_data($attributes); |
|
| 24 | 24 | // Set this so filter blocks being used as widgets know when to render. |
| 25 | - $this->asset_data_registry->add( 'has_filterable_products', true, true ); |
|
| 25 | + $this->asset_data_registry->add('has_filterable_products', true, true); |
|
| 26 | 26 | |
| 27 | - $this->asset_data_registry->add( 'min_columns', wc_get_theme_support( 'product_blocks::min_columns', 1 ), true ); |
|
| 28 | - $this->asset_data_registry->add( 'max_columns', wc_get_theme_support( 'product_blocks::max_columns', 6 ), true ); |
|
| 29 | - $this->asset_data_registry->add( 'default_columns', wc_get_theme_support( 'product_blocks::default_columns', 3 ), true ); |
|
| 30 | - $this->asset_data_registry->add( 'min_rows', wc_get_theme_support( 'product_blocks::min_rows', 1 ), true ); |
|
| 31 | - $this->asset_data_registry->add( 'max_rows', wc_get_theme_support( 'product_blocks::max_rows', 6 ), true ); |
|
| 32 | - $this->asset_data_registry->add( 'default_rows', wc_get_theme_support( 'product_blocks::default_rows', 3 ), true ); |
|
| 27 | + $this->asset_data_registry->add('min_columns', wc_get_theme_support('product_blocks::min_columns', 1), true); |
|
| 28 | + $this->asset_data_registry->add('max_columns', wc_get_theme_support('product_blocks::max_columns', 6), true); |
|
| 29 | + $this->asset_data_registry->add('default_columns', wc_get_theme_support('product_blocks::default_columns', 3), true); |
|
| 30 | + $this->asset_data_registry->add('min_rows', wc_get_theme_support('product_blocks::min_rows', 1), true); |
|
| 31 | + $this->asset_data_registry->add('max_rows', wc_get_theme_support('product_blocks::max_rows', 6), true); |
|
| 32 | + $this->asset_data_registry->add('default_rows', wc_get_theme_support('product_blocks::default_rows', 3), true); |
|
| 33 | 33 | $this->hydrate_from_api(); |
| 34 | 34 | } |
| 35 | 35 | |
@@ -37,6 +37,6 @@ discard block |
||
| 37 | 37 | * Hydrate the All Product block with data from the API. |
| 38 | 38 | */ |
| 39 | 39 | protected function hydrate_from_api() { |
| 40 | - $this->asset_data_registry->hydrate_api_request( '/wc/store/v1/cart' ); |
|
| 40 | + $this->asset_data_registry->hydrate_api_request('/wc/store/v1/cart'); |
|
| 41 | 41 | } |
| 42 | 42 | } |
@@ -5,46 +5,46 @@ |
||
| 5 | 5 | * SingleProduct class. |
| 6 | 6 | */ |
| 7 | 7 | class SingleProduct extends AbstractBlock { |
| 8 | - /** |
|
| 9 | - * Block name. |
|
| 10 | - * |
|
| 11 | - * @var string |
|
| 12 | - */ |
|
| 13 | - protected $block_name = 'single-product'; |
|
| 8 | + /** |
|
| 9 | + * Block name. |
|
| 10 | + * |
|
| 11 | + * @var string |
|
| 12 | + */ |
|
| 13 | + protected $block_name = 'single-product'; |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Enqueue frontend assets for this block, just in time for rendering. |
|
| 17 | - * |
|
| 18 | - * @param array $attributes Any attributes that currently are available from the block. |
|
| 19 | - */ |
|
| 20 | - protected function enqueue_assets( array $attributes ) { |
|
| 21 | - parent::enqueue_assets( $attributes ); |
|
| 22 | - $product_id = intval( $attributes['productId'] ); |
|
| 23 | - $this->hydrate_from_api( $product_id ); |
|
| 24 | - } |
|
| 15 | + /** |
|
| 16 | + * Enqueue frontend assets for this block, just in time for rendering. |
|
| 17 | + * |
|
| 18 | + * @param array $attributes Any attributes that currently are available from the block. |
|
| 19 | + */ |
|
| 20 | + protected function enqueue_assets( array $attributes ) { |
|
| 21 | + parent::enqueue_assets( $attributes ); |
|
| 22 | + $product_id = intval( $attributes['productId'] ); |
|
| 23 | + $this->hydrate_from_api( $product_id ); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Get the editor script handle for this block type. |
|
| 28 | - * |
|
| 29 | - * @param string $key Data to get, or default to everything. |
|
| 30 | - * @return array|string; |
|
| 31 | - */ |
|
| 32 | - protected function get_block_type_editor_script( $key = null ) { |
|
| 33 | - $script = [ |
|
| 34 | - 'handle' => 'wc-' . $this->block_name . '-block', |
|
| 35 | - 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name ), |
|
| 36 | - 'dependencies' => [ 'wc-blocks' ], |
|
| 37 | - ]; |
|
| 38 | - return $key ? $script[ $key ] : $script; |
|
| 39 | - } |
|
| 26 | + /** |
|
| 27 | + * Get the editor script handle for this block type. |
|
| 28 | + * |
|
| 29 | + * @param string $key Data to get, or default to everything. |
|
| 30 | + * @return array|string; |
|
| 31 | + */ |
|
| 32 | + protected function get_block_type_editor_script( $key = null ) { |
|
| 33 | + $script = [ |
|
| 34 | + 'handle' => 'wc-' . $this->block_name . '-block', |
|
| 35 | + 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name ), |
|
| 36 | + 'dependencies' => [ 'wc-blocks' ], |
|
| 37 | + ]; |
|
| 38 | + return $key ? $script[ $key ] : $script; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Hydrate the Single Product block with data from the API. |
|
| 43 | - * |
|
| 44 | - * @param int $product_id ID of the product. |
|
| 45 | - */ |
|
| 46 | - protected function hydrate_from_api( int $product_id ) { |
|
| 47 | - $this->asset_data_registry->hydrate_api_request( "/wc/store/v1/products/$product_id" ); |
|
| 48 | - $this->asset_data_registry->hydrate_api_request( '/wc/store/v1/cart' ); |
|
| 49 | - } |
|
| 41 | + /** |
|
| 42 | + * Hydrate the Single Product block with data from the API. |
|
| 43 | + * |
|
| 44 | + * @param int $product_id ID of the product. |
|
| 45 | + */ |
|
| 46 | + protected function hydrate_from_api( int $product_id ) { |
|
| 47 | + $this->asset_data_registry->hydrate_api_request( "/wc/store/v1/products/$product_id" ); |
|
| 48 | + $this->asset_data_registry->hydrate_api_request( '/wc/store/v1/cart' ); |
|
| 49 | + } |
|
| 50 | 50 | } |
@@ -17,10 +17,10 @@ discard block |
||
| 17 | 17 | * |
| 18 | 18 | * @param array $attributes Any attributes that currently are available from the block. |
| 19 | 19 | */ |
| 20 | - protected function enqueue_assets( array $attributes ) { |
|
| 21 | - parent::enqueue_assets( $attributes ); |
|
| 22 | - $product_id = intval( $attributes['productId'] ); |
|
| 23 | - $this->hydrate_from_api( $product_id ); |
|
| 20 | + protected function enqueue_assets(array $attributes) { |
|
| 21 | + parent::enqueue_assets($attributes); |
|
| 22 | + $product_id = intval($attributes['productId']); |
|
| 23 | + $this->hydrate_from_api($product_id); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -29,13 +29,13 @@ discard block |
||
| 29 | 29 | * @param string $key Data to get, or default to everything. |
| 30 | 30 | * @return array|string; |
| 31 | 31 | */ |
| 32 | - protected function get_block_type_editor_script( $key = null ) { |
|
| 32 | + protected function get_block_type_editor_script($key = null) { |
|
| 33 | 33 | $script = [ |
| 34 | 34 | 'handle' => 'wc-' . $this->block_name . '-block', |
| 35 | - 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name ), |
|
| 36 | - 'dependencies' => [ 'wc-blocks' ], |
|
| 35 | + 'path' => $this->asset_api->get_block_asset_build_path($this->block_name), |
|
| 36 | + 'dependencies' => ['wc-blocks'], |
|
| 37 | 37 | ]; |
| 38 | - return $key ? $script[ $key ] : $script; |
|
| 38 | + return $key ? $script[$key] : $script; |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @param int $product_id ID of the product. |
| 45 | 45 | */ |
| 46 | - protected function hydrate_from_api( int $product_id ) { |
|
| 47 | - $this->asset_data_registry->hydrate_api_request( "/wc/store/v1/products/$product_id" ); |
|
| 48 | - $this->asset_data_registry->hydrate_api_request( '/wc/store/v1/cart' ); |
|
| 46 | + protected function hydrate_from_api(int $product_id) { |
|
| 47 | + $this->asset_data_registry->hydrate_api_request("/wc/store/v1/products/$product_id"); |
|
| 48 | + $this->asset_data_registry->hydrate_api_request('/wc/store/v1/cart'); |
|
| 49 | 49 | } |
| 50 | 50 | } |
@@ -16,377 +16,377 @@ discard block |
||
| 16 | 16 | * @internal |
| 17 | 17 | */ |
| 18 | 18 | class MiniCart extends AbstractBlock { |
| 19 | - /** |
|
| 20 | - * Block name. |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $block_name = 'mini-cart'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Chunks build folder. |
|
| 28 | - * |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - protected $chunks_folder = 'mini-cart-contents-block'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Array of scripts that will be lazy loaded when interacting with the block. |
|
| 35 | - * |
|
| 36 | - * @var string[] |
|
| 37 | - */ |
|
| 38 | - protected $scripts_to_lazy_load = array(); |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Inc Tax label. |
|
| 42 | - * |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - protected $tax_label = ''; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Visibility of price including tax. |
|
| 49 | - * |
|
| 50 | - * @var string |
|
| 51 | - */ |
|
| 52 | - protected $display_cart_prices_including_tax = false; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Constructor. |
|
| 56 | - * |
|
| 57 | - * @param AssetApi $asset_api Instance of the asset API. |
|
| 58 | - * @param AssetDataRegistry $asset_data_registry Instance of the asset data registry. |
|
| 59 | - * @param IntegrationRegistry $integration_registry Instance of the integration registry. |
|
| 60 | - */ |
|
| 61 | - public function __construct( AssetApi $asset_api, AssetDataRegistry $asset_data_registry, IntegrationRegistry $integration_registry ) { |
|
| 62 | - parent::__construct( $asset_api, $asset_data_registry, $integration_registry, $this->block_name ); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Initialize this block type. |
|
| 67 | - * |
|
| 68 | - * - Hook into WP lifecycle. |
|
| 69 | - * - Register the block with WordPress. |
|
| 70 | - */ |
|
| 71 | - protected function initialize() { |
|
| 72 | - parent::initialize(); |
|
| 73 | - add_action( 'wp_loaded', array( $this, 'register_empty_cart_message_block_pattern' ) ); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Get the editor script handle for this block type. |
|
| 78 | - * |
|
| 79 | - * @param string $key Data to get, or default to everything. |
|
| 80 | - * @return array|string; |
|
| 81 | - */ |
|
| 82 | - protected function get_block_type_editor_script( $key = null ) { |
|
| 83 | - $script = [ |
|
| 84 | - 'handle' => 'wc-' . $this->block_name . '-block', |
|
| 85 | - 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name ), |
|
| 86 | - 'dependencies' => [ 'wc-blocks' ], |
|
| 87 | - ]; |
|
| 88 | - return $key ? $script[ $key ] : $script; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Get the frontend script handle for this block type. |
|
| 93 | - * |
|
| 94 | - * @see $this->register_block_type() |
|
| 95 | - * @param string $key Data to get, or default to everything. |
|
| 96 | - * @return array|string |
|
| 97 | - */ |
|
| 98 | - protected function get_block_type_script( $key = null ) { |
|
| 99 | - if ( is_cart() || is_checkout() ) { |
|
| 100 | - return; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - $script = [ |
|
| 104 | - 'handle' => 'wc-' . $this->block_name . '-block-frontend', |
|
| 105 | - 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name . '-frontend' ), |
|
| 106 | - 'dependencies' => [], |
|
| 107 | - ]; |
|
| 108 | - return $key ? $script[ $key ] : $script; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Extra data passed through from server to client for block. |
|
| 113 | - * |
|
| 114 | - * @param array $attributes Any attributes that currently are available from the block. |
|
| 115 | - * Note, this will be empty in the editor context when the block is |
|
| 116 | - * not in the post content on editor load. |
|
| 117 | - */ |
|
| 118 | - protected function enqueue_data( array $attributes = [] ) { |
|
| 119 | - if ( is_cart() || is_checkout() ) { |
|
| 120 | - return; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - parent::enqueue_data( $attributes ); |
|
| 124 | - |
|
| 125 | - // Hydrate the following data depending on admin or frontend context. |
|
| 126 | - if ( ! is_admin() && ! WC()->is_rest_api_request() ) { |
|
| 127 | - $label_info = $this->get_tax_label(); |
|
| 128 | - |
|
| 129 | - $this->tax_label = $label_info['tax_label']; |
|
| 130 | - $this->display_cart_prices_including_tax = $label_info['display_cart_prices_including_tax']; |
|
| 131 | - |
|
| 132 | - $this->asset_data_registry->add( |
|
| 133 | - 'taxLabel', |
|
| 134 | - $this->tax_label, |
|
| 135 | - '' |
|
| 136 | - ); |
|
| 137 | - |
|
| 138 | - $cart_payload = $this->get_cart_payload(); |
|
| 139 | - |
|
| 140 | - $this->asset_data_registry->add( |
|
| 141 | - 'cartTotals', |
|
| 142 | - isset( $cart_payload['totals'] ) ? $cart_payload['totals'] : null, |
|
| 143 | - null |
|
| 144 | - ); |
|
| 145 | - |
|
| 146 | - $this->asset_data_registry->add( |
|
| 147 | - 'cartItemsCount', |
|
| 148 | - isset( $cart_payload['items_count'] ) ? $cart_payload['items_count'] : null, |
|
| 149 | - null |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - $script_data = $this->asset_api->get_script_data( 'build/mini-cart-component-frontend.js' ); |
|
| 154 | - |
|
| 155 | - $num_dependencies = count( $script_data['dependencies'] ); |
|
| 156 | - $wp_scripts = wp_scripts(); |
|
| 157 | - |
|
| 158 | - for ( $i = 0; $i < $num_dependencies; $i++ ) { |
|
| 159 | - $dependency = $script_data['dependencies'][ $i ]; |
|
| 160 | - |
|
| 161 | - foreach ( $wp_scripts->registered as $script ) { |
|
| 162 | - if ( $script->handle === $dependency ) { |
|
| 163 | - $this->append_script_and_deps_src( $script ); |
|
| 164 | - break; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - $payment_method_registry = Package::container()->get( PaymentMethodRegistry::class ); |
|
| 170 | - $payment_methods = $payment_method_registry->get_all_active_payment_method_script_dependencies(); |
|
| 171 | - |
|
| 172 | - foreach ( $payment_methods as $payment_method ) { |
|
| 173 | - $payment_method_script = $this->get_script_from_handle( $payment_method ); |
|
| 174 | - |
|
| 175 | - if ( ! is_null( $payment_method_script ) ) { |
|
| 176 | - $this->append_script_and_deps_src( $payment_method_script ); |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - $this->scripts_to_lazy_load['wc-block-mini-cart-component-frontend'] = array( |
|
| 181 | - 'src' => $script_data['src'], |
|
| 182 | - 'version' => $script_data['version'], |
|
| 183 | - 'translations' => $this->get_inner_blocks_translations(), |
|
| 184 | - ); |
|
| 185 | - |
|
| 186 | - $this->asset_data_registry->add( |
|
| 187 | - 'mini_cart_block_frontend_dependencies', |
|
| 188 | - $this->scripts_to_lazy_load, |
|
| 189 | - true |
|
| 190 | - ); |
|
| 191 | - |
|
| 192 | - $this->asset_data_registry->add( |
|
| 193 | - 'displayCartPricesIncludingTax', |
|
| 194 | - $this->display_cart_prices_including_tax, |
|
| 195 | - true |
|
| 196 | - ); |
|
| 197 | - |
|
| 198 | - $template_part_edit_uri = ''; |
|
| 199 | - |
|
| 200 | - if ( |
|
| 201 | - current_user_can( 'edit_theme_options' ) && |
|
| 202 | - wc_current_theme_is_fse_theme() |
|
| 203 | - ) { |
|
| 204 | - $theme_slug = BlockTemplateUtils::theme_has_template_part( 'mini-cart' ) ? wp_get_theme()->get_stylesheet() : BlockTemplateUtils::PLUGIN_SLUG; |
|
| 205 | - $site_editor_uri = admin_url( 'site-editor.php' ); |
|
| 206 | - |
|
| 207 | - if ( version_compare( get_bloginfo( 'version' ), '5.9', '<' ) ) { |
|
| 208 | - $site_editor_uri = add_query_arg( |
|
| 209 | - array( 'page' => 'gutenberg-edit-site' ), |
|
| 210 | - admin_url( 'themes.php' ) |
|
| 211 | - ); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $template_part_edit_uri = add_query_arg( |
|
| 215 | - array( |
|
| 216 | - 'postId' => sprintf( '%s//%s', $theme_slug, 'mini-cart' ), |
|
| 217 | - 'postType' => 'wp_template_part', |
|
| 218 | - ), |
|
| 219 | - $site_editor_uri |
|
| 220 | - ); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - $this->asset_data_registry->add( |
|
| 224 | - 'templatePartEditUri', |
|
| 225 | - $template_part_edit_uri, |
|
| 226 | - '' |
|
| 227 | - ); |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Fires after cart block data is registered. |
|
| 231 | - */ |
|
| 232 | - do_action( 'woocommerce_blocks_cart_enqueue_data' ); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * Returns the script data given its handle. |
|
| 237 | - * |
|
| 238 | - * @param string $handle Handle of the script. |
|
| 239 | - * |
|
| 240 | - * @return \_WP_Dependency|null Object containing the script data if found, or null. |
|
| 241 | - */ |
|
| 242 | - protected function get_script_from_handle( $handle ) { |
|
| 243 | - $wp_scripts = wp_scripts(); |
|
| 244 | - foreach ( $wp_scripts->registered as $script ) { |
|
| 245 | - if ( $script->handle === $handle ) { |
|
| 246 | - return $script; |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - return null; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Recursively appends a scripts and its dependencies into the scripts_to_lazy_load array. |
|
| 254 | - * |
|
| 255 | - * @param \_WP_Dependency $script Object containing script data. |
|
| 256 | - */ |
|
| 257 | - protected function append_script_and_deps_src( $script ) { |
|
| 258 | - $wp_scripts = wp_scripts(); |
|
| 259 | - |
|
| 260 | - // This script and its dependencies have already been appended. |
|
| 261 | - if ( ! $script || array_key_exists( $script->handle, $this->scripts_to_lazy_load ) ) { |
|
| 262 | - return; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - if ( count( $script->deps ) ) { |
|
| 266 | - foreach ( $script->deps as $dep ) { |
|
| 267 | - if ( ! array_key_exists( $dep, $this->scripts_to_lazy_load ) ) { |
|
| 268 | - $dep_script = $this->get_script_from_handle( $dep ); |
|
| 269 | - |
|
| 270 | - if ( ! is_null( $dep_script ) ) { |
|
| 271 | - $this->append_script_and_deps_src( $dep_script ); |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - if ( ! $script->src ) { |
|
| 277 | - return; |
|
| 278 | - } |
|
| 279 | - $this->scripts_to_lazy_load[ $script->handle ] = array( |
|
| 280 | - 'src' => $script->src, |
|
| 281 | - 'version' => $script->ver, |
|
| 282 | - 'before' => $wp_scripts->print_inline_script( $script->handle, 'before', false ), |
|
| 283 | - 'after' => $wp_scripts->print_inline_script( $script->handle, 'after', false ), |
|
| 284 | - 'translations' => $wp_scripts->print_translations( $script->handle, false ), |
|
| 285 | - ); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Returns the markup for render the tax label. |
|
| 290 | - * |
|
| 291 | - * @return string |
|
| 292 | - */ |
|
| 293 | - protected function get_include_tax_label_markup() { |
|
| 294 | - $cart_controller = $this->get_cart_controller(); |
|
| 295 | - $cart = $cart_controller->get_cart_instance(); |
|
| 296 | - $cart_contents_total = $cart->get_subtotal(); |
|
| 297 | - |
|
| 298 | - return ( ! empty( $this->tax_label ) && 0 !== $cart_contents_total ) ? ( "<small class='wc-block-mini-cart__tax-label'>" . esc_html( $this->tax_label ) . '</small>' ) : ''; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Append frontend scripts when rendering the Mini Cart block. |
|
| 303 | - * |
|
| 304 | - * @param array $attributes Block attributes. |
|
| 305 | - * @param string $content Block content. |
|
| 306 | - * |
|
| 307 | - * @return string Rendered block type output. |
|
| 308 | - */ |
|
| 309 | - protected function render( $attributes, $content ) { |
|
| 310 | - return $content . $this->get_markup( $attributes ); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Render the markup for the Mini Cart block. |
|
| 315 | - * |
|
| 316 | - * @param array $attributes Block attributes. |
|
| 317 | - * |
|
| 318 | - * @return string The HTML markup. |
|
| 319 | - */ |
|
| 320 | - protected function get_markup( $attributes ) { |
|
| 321 | - if ( is_admin() || WC()->is_rest_api_request() ) { |
|
| 322 | - // In the editor we will display the placeholder, so no need to load |
|
| 323 | - // real cart data and to print the markup. |
|
| 324 | - return ''; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - $cart_controller = $this->get_cart_controller(); |
|
| 328 | - $cart = $cart_controller->get_cart_instance(); |
|
| 329 | - $cart_contents_count = $cart->get_cart_contents_count(); |
|
| 330 | - $cart_contents = $cart->get_cart(); |
|
| 331 | - $cart_contents_total = $cart->get_subtotal(); |
|
| 332 | - |
|
| 333 | - if ( $cart->display_prices_including_tax() ) { |
|
| 334 | - $cart_contents_total += $cart->get_subtotal_tax(); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - $classes_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, array( 'text_color', 'background_color', 'font_size', 'font_family' ) ); |
|
| 338 | - $wrapper_classes = sprintf( 'wc-block-mini-cart wp-block-woocommerce-mini-cart %s', $classes_styles['classes'] ); |
|
| 339 | - $wrapper_styles = $classes_styles['styles']; |
|
| 340 | - |
|
| 341 | - $aria_label = sprintf( |
|
| 342 | - /* translators: %1$d is the number of products in the cart. %2$s is the cart total */ |
|
| 343 | - _n( |
|
| 344 | - '%1$d item in cart, total price of %2$s', |
|
| 345 | - '%1$d items in cart, total price of %2$s', |
|
| 346 | - $cart_contents_count, |
|
| 347 | - 'woocommerce' |
|
| 348 | - ), |
|
| 349 | - $cart_contents_count, |
|
| 350 | - wp_strip_all_tags( wc_price( $cart_contents_total ) ) |
|
| 351 | - ); |
|
| 352 | - $icon = '<svg class="wc-block-mini-cart__icon" width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"> |
|
| 19 | + /** |
|
| 20 | + * Block name. |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $block_name = 'mini-cart'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Chunks build folder. |
|
| 28 | + * |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + protected $chunks_folder = 'mini-cart-contents-block'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Array of scripts that will be lazy loaded when interacting with the block. |
|
| 35 | + * |
|
| 36 | + * @var string[] |
|
| 37 | + */ |
|
| 38 | + protected $scripts_to_lazy_load = array(); |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Inc Tax label. |
|
| 42 | + * |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + protected $tax_label = ''; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Visibility of price including tax. |
|
| 49 | + * |
|
| 50 | + * @var string |
|
| 51 | + */ |
|
| 52 | + protected $display_cart_prices_including_tax = false; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Constructor. |
|
| 56 | + * |
|
| 57 | + * @param AssetApi $asset_api Instance of the asset API. |
|
| 58 | + * @param AssetDataRegistry $asset_data_registry Instance of the asset data registry. |
|
| 59 | + * @param IntegrationRegistry $integration_registry Instance of the integration registry. |
|
| 60 | + */ |
|
| 61 | + public function __construct( AssetApi $asset_api, AssetDataRegistry $asset_data_registry, IntegrationRegistry $integration_registry ) { |
|
| 62 | + parent::__construct( $asset_api, $asset_data_registry, $integration_registry, $this->block_name ); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Initialize this block type. |
|
| 67 | + * |
|
| 68 | + * - Hook into WP lifecycle. |
|
| 69 | + * - Register the block with WordPress. |
|
| 70 | + */ |
|
| 71 | + protected function initialize() { |
|
| 72 | + parent::initialize(); |
|
| 73 | + add_action( 'wp_loaded', array( $this, 'register_empty_cart_message_block_pattern' ) ); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Get the editor script handle for this block type. |
|
| 78 | + * |
|
| 79 | + * @param string $key Data to get, or default to everything. |
|
| 80 | + * @return array|string; |
|
| 81 | + */ |
|
| 82 | + protected function get_block_type_editor_script( $key = null ) { |
|
| 83 | + $script = [ |
|
| 84 | + 'handle' => 'wc-' . $this->block_name . '-block', |
|
| 85 | + 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name ), |
|
| 86 | + 'dependencies' => [ 'wc-blocks' ], |
|
| 87 | + ]; |
|
| 88 | + return $key ? $script[ $key ] : $script; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Get the frontend script handle for this block type. |
|
| 93 | + * |
|
| 94 | + * @see $this->register_block_type() |
|
| 95 | + * @param string $key Data to get, or default to everything. |
|
| 96 | + * @return array|string |
|
| 97 | + */ |
|
| 98 | + protected function get_block_type_script( $key = null ) { |
|
| 99 | + if ( is_cart() || is_checkout() ) { |
|
| 100 | + return; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + $script = [ |
|
| 104 | + 'handle' => 'wc-' . $this->block_name . '-block-frontend', |
|
| 105 | + 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name . '-frontend' ), |
|
| 106 | + 'dependencies' => [], |
|
| 107 | + ]; |
|
| 108 | + return $key ? $script[ $key ] : $script; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Extra data passed through from server to client for block. |
|
| 113 | + * |
|
| 114 | + * @param array $attributes Any attributes that currently are available from the block. |
|
| 115 | + * Note, this will be empty in the editor context when the block is |
|
| 116 | + * not in the post content on editor load. |
|
| 117 | + */ |
|
| 118 | + protected function enqueue_data( array $attributes = [] ) { |
|
| 119 | + if ( is_cart() || is_checkout() ) { |
|
| 120 | + return; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + parent::enqueue_data( $attributes ); |
|
| 124 | + |
|
| 125 | + // Hydrate the following data depending on admin or frontend context. |
|
| 126 | + if ( ! is_admin() && ! WC()->is_rest_api_request() ) { |
|
| 127 | + $label_info = $this->get_tax_label(); |
|
| 128 | + |
|
| 129 | + $this->tax_label = $label_info['tax_label']; |
|
| 130 | + $this->display_cart_prices_including_tax = $label_info['display_cart_prices_including_tax']; |
|
| 131 | + |
|
| 132 | + $this->asset_data_registry->add( |
|
| 133 | + 'taxLabel', |
|
| 134 | + $this->tax_label, |
|
| 135 | + '' |
|
| 136 | + ); |
|
| 137 | + |
|
| 138 | + $cart_payload = $this->get_cart_payload(); |
|
| 139 | + |
|
| 140 | + $this->asset_data_registry->add( |
|
| 141 | + 'cartTotals', |
|
| 142 | + isset( $cart_payload['totals'] ) ? $cart_payload['totals'] : null, |
|
| 143 | + null |
|
| 144 | + ); |
|
| 145 | + |
|
| 146 | + $this->asset_data_registry->add( |
|
| 147 | + 'cartItemsCount', |
|
| 148 | + isset( $cart_payload['items_count'] ) ? $cart_payload['items_count'] : null, |
|
| 149 | + null |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + $script_data = $this->asset_api->get_script_data( 'build/mini-cart-component-frontend.js' ); |
|
| 154 | + |
|
| 155 | + $num_dependencies = count( $script_data['dependencies'] ); |
|
| 156 | + $wp_scripts = wp_scripts(); |
|
| 157 | + |
|
| 158 | + for ( $i = 0; $i < $num_dependencies; $i++ ) { |
|
| 159 | + $dependency = $script_data['dependencies'][ $i ]; |
|
| 160 | + |
|
| 161 | + foreach ( $wp_scripts->registered as $script ) { |
|
| 162 | + if ( $script->handle === $dependency ) { |
|
| 163 | + $this->append_script_and_deps_src( $script ); |
|
| 164 | + break; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + $payment_method_registry = Package::container()->get( PaymentMethodRegistry::class ); |
|
| 170 | + $payment_methods = $payment_method_registry->get_all_active_payment_method_script_dependencies(); |
|
| 171 | + |
|
| 172 | + foreach ( $payment_methods as $payment_method ) { |
|
| 173 | + $payment_method_script = $this->get_script_from_handle( $payment_method ); |
|
| 174 | + |
|
| 175 | + if ( ! is_null( $payment_method_script ) ) { |
|
| 176 | + $this->append_script_and_deps_src( $payment_method_script ); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + $this->scripts_to_lazy_load['wc-block-mini-cart-component-frontend'] = array( |
|
| 181 | + 'src' => $script_data['src'], |
|
| 182 | + 'version' => $script_data['version'], |
|
| 183 | + 'translations' => $this->get_inner_blocks_translations(), |
|
| 184 | + ); |
|
| 185 | + |
|
| 186 | + $this->asset_data_registry->add( |
|
| 187 | + 'mini_cart_block_frontend_dependencies', |
|
| 188 | + $this->scripts_to_lazy_load, |
|
| 189 | + true |
|
| 190 | + ); |
|
| 191 | + |
|
| 192 | + $this->asset_data_registry->add( |
|
| 193 | + 'displayCartPricesIncludingTax', |
|
| 194 | + $this->display_cart_prices_including_tax, |
|
| 195 | + true |
|
| 196 | + ); |
|
| 197 | + |
|
| 198 | + $template_part_edit_uri = ''; |
|
| 199 | + |
|
| 200 | + if ( |
|
| 201 | + current_user_can( 'edit_theme_options' ) && |
|
| 202 | + wc_current_theme_is_fse_theme() |
|
| 203 | + ) { |
|
| 204 | + $theme_slug = BlockTemplateUtils::theme_has_template_part( 'mini-cart' ) ? wp_get_theme()->get_stylesheet() : BlockTemplateUtils::PLUGIN_SLUG; |
|
| 205 | + $site_editor_uri = admin_url( 'site-editor.php' ); |
|
| 206 | + |
|
| 207 | + if ( version_compare( get_bloginfo( 'version' ), '5.9', '<' ) ) { |
|
| 208 | + $site_editor_uri = add_query_arg( |
|
| 209 | + array( 'page' => 'gutenberg-edit-site' ), |
|
| 210 | + admin_url( 'themes.php' ) |
|
| 211 | + ); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $template_part_edit_uri = add_query_arg( |
|
| 215 | + array( |
|
| 216 | + 'postId' => sprintf( '%s//%s', $theme_slug, 'mini-cart' ), |
|
| 217 | + 'postType' => 'wp_template_part', |
|
| 218 | + ), |
|
| 219 | + $site_editor_uri |
|
| 220 | + ); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + $this->asset_data_registry->add( |
|
| 224 | + 'templatePartEditUri', |
|
| 225 | + $template_part_edit_uri, |
|
| 226 | + '' |
|
| 227 | + ); |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Fires after cart block data is registered. |
|
| 231 | + */ |
|
| 232 | + do_action( 'woocommerce_blocks_cart_enqueue_data' ); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * Returns the script data given its handle. |
|
| 237 | + * |
|
| 238 | + * @param string $handle Handle of the script. |
|
| 239 | + * |
|
| 240 | + * @return \_WP_Dependency|null Object containing the script data if found, or null. |
|
| 241 | + */ |
|
| 242 | + protected function get_script_from_handle( $handle ) { |
|
| 243 | + $wp_scripts = wp_scripts(); |
|
| 244 | + foreach ( $wp_scripts->registered as $script ) { |
|
| 245 | + if ( $script->handle === $handle ) { |
|
| 246 | + return $script; |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + return null; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Recursively appends a scripts and its dependencies into the scripts_to_lazy_load array. |
|
| 254 | + * |
|
| 255 | + * @param \_WP_Dependency $script Object containing script data. |
|
| 256 | + */ |
|
| 257 | + protected function append_script_and_deps_src( $script ) { |
|
| 258 | + $wp_scripts = wp_scripts(); |
|
| 259 | + |
|
| 260 | + // This script and its dependencies have already been appended. |
|
| 261 | + if ( ! $script || array_key_exists( $script->handle, $this->scripts_to_lazy_load ) ) { |
|
| 262 | + return; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + if ( count( $script->deps ) ) { |
|
| 266 | + foreach ( $script->deps as $dep ) { |
|
| 267 | + if ( ! array_key_exists( $dep, $this->scripts_to_lazy_load ) ) { |
|
| 268 | + $dep_script = $this->get_script_from_handle( $dep ); |
|
| 269 | + |
|
| 270 | + if ( ! is_null( $dep_script ) ) { |
|
| 271 | + $this->append_script_and_deps_src( $dep_script ); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + if ( ! $script->src ) { |
|
| 277 | + return; |
|
| 278 | + } |
|
| 279 | + $this->scripts_to_lazy_load[ $script->handle ] = array( |
|
| 280 | + 'src' => $script->src, |
|
| 281 | + 'version' => $script->ver, |
|
| 282 | + 'before' => $wp_scripts->print_inline_script( $script->handle, 'before', false ), |
|
| 283 | + 'after' => $wp_scripts->print_inline_script( $script->handle, 'after', false ), |
|
| 284 | + 'translations' => $wp_scripts->print_translations( $script->handle, false ), |
|
| 285 | + ); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Returns the markup for render the tax label. |
|
| 290 | + * |
|
| 291 | + * @return string |
|
| 292 | + */ |
|
| 293 | + protected function get_include_tax_label_markup() { |
|
| 294 | + $cart_controller = $this->get_cart_controller(); |
|
| 295 | + $cart = $cart_controller->get_cart_instance(); |
|
| 296 | + $cart_contents_total = $cart->get_subtotal(); |
|
| 297 | + |
|
| 298 | + return ( ! empty( $this->tax_label ) && 0 !== $cart_contents_total ) ? ( "<small class='wc-block-mini-cart__tax-label'>" . esc_html( $this->tax_label ) . '</small>' ) : ''; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Append frontend scripts when rendering the Mini Cart block. |
|
| 303 | + * |
|
| 304 | + * @param array $attributes Block attributes. |
|
| 305 | + * @param string $content Block content. |
|
| 306 | + * |
|
| 307 | + * @return string Rendered block type output. |
|
| 308 | + */ |
|
| 309 | + protected function render( $attributes, $content ) { |
|
| 310 | + return $content . $this->get_markup( $attributes ); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Render the markup for the Mini Cart block. |
|
| 315 | + * |
|
| 316 | + * @param array $attributes Block attributes. |
|
| 317 | + * |
|
| 318 | + * @return string The HTML markup. |
|
| 319 | + */ |
|
| 320 | + protected function get_markup( $attributes ) { |
|
| 321 | + if ( is_admin() || WC()->is_rest_api_request() ) { |
|
| 322 | + // In the editor we will display the placeholder, so no need to load |
|
| 323 | + // real cart data and to print the markup. |
|
| 324 | + return ''; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + $cart_controller = $this->get_cart_controller(); |
|
| 328 | + $cart = $cart_controller->get_cart_instance(); |
|
| 329 | + $cart_contents_count = $cart->get_cart_contents_count(); |
|
| 330 | + $cart_contents = $cart->get_cart(); |
|
| 331 | + $cart_contents_total = $cart->get_subtotal(); |
|
| 332 | + |
|
| 333 | + if ( $cart->display_prices_including_tax() ) { |
|
| 334 | + $cart_contents_total += $cart->get_subtotal_tax(); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + $classes_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, array( 'text_color', 'background_color', 'font_size', 'font_family' ) ); |
|
| 338 | + $wrapper_classes = sprintf( 'wc-block-mini-cart wp-block-woocommerce-mini-cart %s', $classes_styles['classes'] ); |
|
| 339 | + $wrapper_styles = $classes_styles['styles']; |
|
| 340 | + |
|
| 341 | + $aria_label = sprintf( |
|
| 342 | + /* translators: %1$d is the number of products in the cart. %2$s is the cart total */ |
|
| 343 | + _n( |
|
| 344 | + '%1$d item in cart, total price of %2$s', |
|
| 345 | + '%1$d items in cart, total price of %2$s', |
|
| 346 | + $cart_contents_count, |
|
| 347 | + 'woocommerce' |
|
| 348 | + ), |
|
| 349 | + $cart_contents_count, |
|
| 350 | + wp_strip_all_tags( wc_price( $cart_contents_total ) ) |
|
| 351 | + ); |
|
| 352 | + $icon = '<svg class="wc-block-mini-cart__icon" width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"> |
|
| 353 | 353 | <path fill-rule="evenodd" clip-rule="evenodd" d="M7.84614 18.2769C7.89712 18.2769 7.93845 18.2356 7.93845 18.1846C7.93845 18.1336 7.89712 18.0923 7.84614 18.0923C7.79516 18.0923 7.75384 18.1336 7.75384 18.1846C7.75384 18.2356 7.79516 18.2769 7.84614 18.2769ZM6.03076 18.1846C6.03076 17.182 6.84353 16.3692 7.84614 16.3692C8.84875 16.3692 9.66152 17.182 9.66152 18.1846C9.66152 19.1872 8.84875 20 7.84614 20C6.84353 20 6.03076 19.1872 6.03076 18.1846Z" fill="currentColor"/> |
| 354 | 354 | <path fill-rule="evenodd" clip-rule="evenodd" d="M17.3231 18.2769C17.3741 18.2769 17.4154 18.2356 17.4154 18.1846C17.4154 18.1336 17.3741 18.0923 17.3231 18.0923C17.2721 18.0923 17.2308 18.1336 17.2308 18.1846C17.2308 18.2356 17.2721 18.2769 17.3231 18.2769ZM15.5077 18.1846C15.5077 17.182 16.3205 16.3692 17.3231 16.3692C18.3257 16.3692 19.1385 17.182 19.1385 18.1846C19.1385 19.1872 18.3257 20 17.3231 20C16.3205 20 15.5077 19.1872 15.5077 18.1846Z" fill="currentColor"/> |
| 355 | 355 | <path fill-rule="evenodd" clip-rule="evenodd" d="M20.0631 9.53835L19.4662 12.6685L19.4648 12.6757L19.4648 12.6757C19.3424 13.2919 19.0072 13.8454 18.5178 14.2394C18.031 14.6312 17.4226 14.8404 16.798 14.8308H8.44017C7.81556 14.8404 7.20714 14.6312 6.72038 14.2394C6.2312 13.8456 5.89605 13.2924 5.77352 12.6765L5.77335 12.6757L4.33477 5.48814C4.3286 5.46282 4.32345 5.43711 4.31934 5.41104L3.61815 1.90768H0.953842C0.42705 1.90768 0 1.48063 0 0.953842C0 0.42705 0.42705 0 0.953842 0H4.4C4.85462 0 5.24607 0.320858 5.33529 0.766644L6.04403 4.30769H12.785C13.0114 4.99157 13.3319 5.63258 13.7312 6.21538H6.42585L7.64421 12.3026L7.64449 12.304C7.67966 12.4811 7.77599 12.6402 7.91662 12.7534C8.05725 12.8666 8.23322 12.9267 8.41372 12.9233L8.432 12.9231H16.8062L16.8244 12.9233C17.0049 12.9267 17.1809 12.8666 17.3215 12.7534C17.4614 12.6408 17.5575 12.4828 17.5931 12.3068L17.5937 12.304L18.1649 9.30867C18.762 9.45873 19.387 9.53842 20.0307 9.53842C20.0415 9.53842 20.0523 9.5384 20.0631 9.53835Z" fill="currentColor"/> |
| 356 | 356 | </svg>'; |
| 357 | - $button_html = '<span class="wc-block-mini-cart__amount">' . esc_html( wp_strip_all_tags( wc_price( $cart_contents_total ) ) ) . '</span> |
|
| 357 | + $button_html = '<span class="wc-block-mini-cart__amount">' . esc_html( wp_strip_all_tags( wc_price( $cart_contents_total ) ) ) . '</span> |
|
| 358 | 358 | ' . $this->get_include_tax_label_markup() . ' |
| 359 | 359 | <span class="wc-block-mini-cart__quantity-badge"> |
| 360 | 360 | ' . $icon . ' |
| 361 | 361 | <span class="wc-block-mini-cart__badge">' . $cart_contents_count . '</span> |
| 362 | 362 | </span>'; |
| 363 | 363 | |
| 364 | - if ( is_cart() || is_checkout() ) { |
|
| 365 | - // It is not necessary to load the Mini Cart Block on Cart and Checkout page. |
|
| 366 | - return '<div class="' . $wrapper_classes . '" style="visibility:hidden" aria-hidden="true"> |
|
| 364 | + if ( is_cart() || is_checkout() ) { |
|
| 365 | + // It is not necessary to load the Mini Cart Block on Cart and Checkout page. |
|
| 366 | + return '<div class="' . $wrapper_classes . '" style="visibility:hidden" aria-hidden="true"> |
|
| 367 | 367 | <button class="wc-block-mini-cart__button" aria-label="' . esc_attr( $aria_label ) . '" disabled>' . $button_html . '</button> |
| 368 | 368 | </div>'; |
| 369 | - } |
|
| 369 | + } |
|
| 370 | 370 | |
| 371 | - $template_part_contents = ''; |
|
| 371 | + $template_part_contents = ''; |
|
| 372 | 372 | |
| 373 | - // Determine if we need to load the template part from the theme, or WooCommerce in that order. |
|
| 374 | - $theme_has_mini_cart = BlockTemplateUtils::theme_has_template_part( 'mini-cart' ); |
|
| 375 | - $template_slug_to_load = $theme_has_mini_cart ? get_stylesheet() : BlockTemplateUtils::PLUGIN_SLUG; |
|
| 376 | - $template_part = BlockTemplateUtils::get_block_template( $template_slug_to_load . '//mini-cart', 'wp_template_part' ); |
|
| 373 | + // Determine if we need to load the template part from the theme, or WooCommerce in that order. |
|
| 374 | + $theme_has_mini_cart = BlockTemplateUtils::theme_has_template_part( 'mini-cart' ); |
|
| 375 | + $template_slug_to_load = $theme_has_mini_cart ? get_stylesheet() : BlockTemplateUtils::PLUGIN_SLUG; |
|
| 376 | + $template_part = BlockTemplateUtils::get_block_template( $template_slug_to_load . '//mini-cart', 'wp_template_part' ); |
|
| 377 | 377 | |
| 378 | - if ( $template_part && ! empty( $template_part->content ) ) { |
|
| 379 | - $template_part_contents = do_blocks( $template_part->content ); |
|
| 380 | - } |
|
| 378 | + if ( $template_part && ! empty( $template_part->content ) ) { |
|
| 379 | + $template_part_contents = do_blocks( $template_part->content ); |
|
| 380 | + } |
|
| 381 | 381 | |
| 382 | - if ( '' === $template_part_contents ) { |
|
| 383 | - $template_part_contents = do_blocks( |
|
| 384 | - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
|
| 385 | - file_get_contents( Package::get_path() . 'templates/' . BlockTemplateUtils::DIRECTORY_NAMES['TEMPLATE_PARTS'] . '/mini-cart.html' ) |
|
| 386 | - ); |
|
| 387 | - } |
|
| 382 | + if ( '' === $template_part_contents ) { |
|
| 383 | + $template_part_contents = do_blocks( |
|
| 384 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
|
| 385 | + file_get_contents( Package::get_path() . 'templates/' . BlockTemplateUtils::DIRECTORY_NAMES['TEMPLATE_PARTS'] . '/mini-cart.html' ) |
|
| 386 | + ); |
|
| 387 | + } |
|
| 388 | 388 | |
| 389 | - return '<div class="' . $wrapper_classes . '" style="' . $wrapper_styles . '"> |
|
| 389 | + return '<div class="' . $wrapper_classes . '" style="' . $wrapper_styles . '"> |
|
| 390 | 390 | <button class="wc-block-mini-cart__button" aria-label="' . esc_attr( $aria_label ) . '">' . $button_html . '</button> |
| 391 | 391 | <div class="wc-block-mini-cart__drawer is-loading is-mobile wc-block-components-drawer__screen-overlay wc-block-components-drawer__screen-overlay--is-hidden" aria-hidden="true"> |
| 392 | 392 | <div class="components-modal__frame wc-block-components-drawer"> |
@@ -395,105 +395,105 @@ discard block |
||
| 395 | 395 | <div class="components-modal__header-heading-container"></div> |
| 396 | 396 | </div> |
| 397 | 397 | <div class="wc-block-mini-cart__template-part">' |
| 398 | - . wp_kses_post( $template_part_contents ) . |
|
| 399 | - '</div> |
|
| 398 | + . wp_kses_post( $template_part_contents ) . |
|
| 399 | + '</div> |
|
| 400 | 400 | </div> |
| 401 | 401 | </div> |
| 402 | 402 | </div> |
| 403 | 403 | </div>'; |
| 404 | - } |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Return an instace of the CartController class. |
|
| 408 | - * |
|
| 409 | - * @return CartController CartController class instance. |
|
| 410 | - */ |
|
| 411 | - protected function get_cart_controller() { |
|
| 412 | - return new CartController(); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * Get array with data for handle the tax label. |
|
| 417 | - * the entire logic of this function is was taken from: |
|
| 418 | - * https://github.com/woocommerce/woocommerce/blob/e730f7463c25b50258e97bf56e31e9d7d3bc7ae7/includes/class-wc-cart.php#L1582 |
|
| 419 | - * |
|
| 420 | - * @return array; |
|
| 421 | - */ |
|
| 422 | - protected function get_tax_label() { |
|
| 423 | - $cart = WC()->cart; |
|
| 424 | - |
|
| 425 | - if ( $cart->display_prices_including_tax() ) { |
|
| 426 | - if ( ! wc_prices_include_tax() ) { |
|
| 427 | - $tax_label = WC()->countries->inc_tax_or_vat(); |
|
| 428 | - $display_cart_prices_including_tax = true; |
|
| 429 | - return array( |
|
| 430 | - 'tax_label' => $tax_label, |
|
| 431 | - 'display_cart_prices_including_tax' => $display_cart_prices_including_tax, |
|
| 432 | - ); |
|
| 433 | - } |
|
| 434 | - return array( |
|
| 435 | - 'tax_label' => '', |
|
| 436 | - 'display_cart_prices_including_tax' => true, |
|
| 437 | - ); |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - if ( wc_prices_include_tax() ) { |
|
| 441 | - $tax_label = WC()->countries->ex_tax_or_vat(); |
|
| 442 | - return array( |
|
| 443 | - 'tax_label' => $tax_label, |
|
| 444 | - 'display_cart_prices_including_tax' => false, |
|
| 445 | - ); |
|
| 446 | - }; |
|
| 447 | - |
|
| 448 | - return array( |
|
| 449 | - 'tax_label' => '', |
|
| 450 | - 'display_cart_prices_including_tax' => false, |
|
| 451 | - ); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * Get Cart Payload. |
|
| 456 | - * |
|
| 457 | - * @return object; |
|
| 458 | - */ |
|
| 459 | - protected function get_cart_payload() { |
|
| 460 | - return WC()->api->get_endpoint_data( '/wc/store/cart' ); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Prepare translations for inner blocks and dependencies. |
|
| 465 | - */ |
|
| 466 | - protected function get_inner_blocks_translations() { |
|
| 467 | - $wp_scripts = wp_scripts(); |
|
| 468 | - $translations = array(); |
|
| 469 | - |
|
| 470 | - $chunks = $this->get_chunks_paths( $this->chunks_folder ); |
|
| 471 | - $vendor_chunks = $this->get_chunks_paths( 'vendors--mini-cart-contents-block' ); |
|
| 472 | - $shared_chunks = [ 'cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend' ]; |
|
| 473 | - |
|
| 474 | - foreach ( array_merge( $chunks, $vendor_chunks, $shared_chunks ) as $chunk ) { |
|
| 475 | - $handle = 'wc-blocks-' . $chunk . '-chunk'; |
|
| 476 | - $this->asset_api->register_script( $handle, $this->asset_api->get_block_asset_build_path( $chunk ), [], true ); |
|
| 477 | - $translations[] = $wp_scripts->print_translations( $handle, false ); |
|
| 478 | - wp_deregister_script( $handle ); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - $translations = array_filter( $translations ); |
|
| 482 | - |
|
| 483 | - return implode( '', $translations ); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * Register block pattern for Empty Cart Message to make it translatable. |
|
| 488 | - */ |
|
| 489 | - public function register_empty_cart_message_block_pattern() { |
|
| 490 | - register_block_pattern( |
|
| 491 | - 'woocommerce/mini-cart-empty-cart-message', |
|
| 492 | - array( |
|
| 493 | - 'title' => __( 'Mini Cart Empty Cart Message', 'woocommerce' ), |
|
| 494 | - 'inserter' => false, |
|
| 495 | - 'content' => '<!-- wp:paragraph {"align":"center"} --><p class="has-text-align-center"><strong>' . __( 'Your cart is currently empty!', 'woocommerce' ) . '</strong></p><!-- /wp:paragraph -->', |
|
| 496 | - ) |
|
| 497 | - ); |
|
| 498 | - } |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * Return an instace of the CartController class. |
|
| 408 | + * |
|
| 409 | + * @return CartController CartController class instance. |
|
| 410 | + */ |
|
| 411 | + protected function get_cart_controller() { |
|
| 412 | + return new CartController(); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * Get array with data for handle the tax label. |
|
| 417 | + * the entire logic of this function is was taken from: |
|
| 418 | + * https://github.com/woocommerce/woocommerce/blob/e730f7463c25b50258e97bf56e31e9d7d3bc7ae7/includes/class-wc-cart.php#L1582 |
|
| 419 | + * |
|
| 420 | + * @return array; |
|
| 421 | + */ |
|
| 422 | + protected function get_tax_label() { |
|
| 423 | + $cart = WC()->cart; |
|
| 424 | + |
|
| 425 | + if ( $cart->display_prices_including_tax() ) { |
|
| 426 | + if ( ! wc_prices_include_tax() ) { |
|
| 427 | + $tax_label = WC()->countries->inc_tax_or_vat(); |
|
| 428 | + $display_cart_prices_including_tax = true; |
|
| 429 | + return array( |
|
| 430 | + 'tax_label' => $tax_label, |
|
| 431 | + 'display_cart_prices_including_tax' => $display_cart_prices_including_tax, |
|
| 432 | + ); |
|
| 433 | + } |
|
| 434 | + return array( |
|
| 435 | + 'tax_label' => '', |
|
| 436 | + 'display_cart_prices_including_tax' => true, |
|
| 437 | + ); |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + if ( wc_prices_include_tax() ) { |
|
| 441 | + $tax_label = WC()->countries->ex_tax_or_vat(); |
|
| 442 | + return array( |
|
| 443 | + 'tax_label' => $tax_label, |
|
| 444 | + 'display_cart_prices_including_tax' => false, |
|
| 445 | + ); |
|
| 446 | + }; |
|
| 447 | + |
|
| 448 | + return array( |
|
| 449 | + 'tax_label' => '', |
|
| 450 | + 'display_cart_prices_including_tax' => false, |
|
| 451 | + ); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * Get Cart Payload. |
|
| 456 | + * |
|
| 457 | + * @return object; |
|
| 458 | + */ |
|
| 459 | + protected function get_cart_payload() { |
|
| 460 | + return WC()->api->get_endpoint_data( '/wc/store/cart' ); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Prepare translations for inner blocks and dependencies. |
|
| 465 | + */ |
|
| 466 | + protected function get_inner_blocks_translations() { |
|
| 467 | + $wp_scripts = wp_scripts(); |
|
| 468 | + $translations = array(); |
|
| 469 | + |
|
| 470 | + $chunks = $this->get_chunks_paths( $this->chunks_folder ); |
|
| 471 | + $vendor_chunks = $this->get_chunks_paths( 'vendors--mini-cart-contents-block' ); |
|
| 472 | + $shared_chunks = [ 'cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend' ]; |
|
| 473 | + |
|
| 474 | + foreach ( array_merge( $chunks, $vendor_chunks, $shared_chunks ) as $chunk ) { |
|
| 475 | + $handle = 'wc-blocks-' . $chunk . '-chunk'; |
|
| 476 | + $this->asset_api->register_script( $handle, $this->asset_api->get_block_asset_build_path( $chunk ), [], true ); |
|
| 477 | + $translations[] = $wp_scripts->print_translations( $handle, false ); |
|
| 478 | + wp_deregister_script( $handle ); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + $translations = array_filter( $translations ); |
|
| 482 | + |
|
| 483 | + return implode( '', $translations ); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * Register block pattern for Empty Cart Message to make it translatable. |
|
| 488 | + */ |
|
| 489 | + public function register_empty_cart_message_block_pattern() { |
|
| 490 | + register_block_pattern( |
|
| 491 | + 'woocommerce/mini-cart-empty-cart-message', |
|
| 492 | + array( |
|
| 493 | + 'title' => __( 'Mini Cart Empty Cart Message', 'woocommerce' ), |
|
| 494 | + 'inserter' => false, |
|
| 495 | + 'content' => '<!-- wp:paragraph {"align":"center"} --><p class="has-text-align-center"><strong>' . __( 'Your cart is currently empty!', 'woocommerce' ) . '</strong></p><!-- /wp:paragraph -->', |
|
| 496 | + ) |
|
| 497 | + ); |
|
| 498 | + } |
|
| 499 | 499 | } |
@@ -58,8 +58,8 @@ discard block |
||
| 58 | 58 | * @param AssetDataRegistry $asset_data_registry Instance of the asset data registry. |
| 59 | 59 | * @param IntegrationRegistry $integration_registry Instance of the integration registry. |
| 60 | 60 | */ |
| 61 | - public function __construct( AssetApi $asset_api, AssetDataRegistry $asset_data_registry, IntegrationRegistry $integration_registry ) { |
|
| 62 | - parent::__construct( $asset_api, $asset_data_registry, $integration_registry, $this->block_name ); |
|
| 61 | + public function __construct(AssetApi $asset_api, AssetDataRegistry $asset_data_registry, IntegrationRegistry $integration_registry) { |
|
| 62 | + parent::__construct($asset_api, $asset_data_registry, $integration_registry, $this->block_name); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | protected function initialize() { |
| 72 | 72 | parent::initialize(); |
| 73 | - add_action( 'wp_loaded', array( $this, 'register_empty_cart_message_block_pattern' ) ); |
|
| 73 | + add_action('wp_loaded', array($this, 'register_empty_cart_message_block_pattern')); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -79,13 +79,13 @@ discard block |
||
| 79 | 79 | * @param string $key Data to get, or default to everything. |
| 80 | 80 | * @return array|string; |
| 81 | 81 | */ |
| 82 | - protected function get_block_type_editor_script( $key = null ) { |
|
| 82 | + protected function get_block_type_editor_script($key = null) { |
|
| 83 | 83 | $script = [ |
| 84 | 84 | 'handle' => 'wc-' . $this->block_name . '-block', |
| 85 | - 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name ), |
|
| 86 | - 'dependencies' => [ 'wc-blocks' ], |
|
| 85 | + 'path' => $this->asset_api->get_block_asset_build_path($this->block_name), |
|
| 86 | + 'dependencies' => ['wc-blocks'], |
|
| 87 | 87 | ]; |
| 88 | - return $key ? $script[ $key ] : $script; |
|
| 88 | + return $key ? $script[$key] : $script; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -95,17 +95,17 @@ discard block |
||
| 95 | 95 | * @param string $key Data to get, or default to everything. |
| 96 | 96 | * @return array|string |
| 97 | 97 | */ |
| 98 | - protected function get_block_type_script( $key = null ) { |
|
| 99 | - if ( is_cart() || is_checkout() ) { |
|
| 98 | + protected function get_block_type_script($key = null) { |
|
| 99 | + if (is_cart() || is_checkout()) { |
|
| 100 | 100 | return; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | $script = [ |
| 104 | 104 | 'handle' => 'wc-' . $this->block_name . '-block-frontend', |
| 105 | - 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name . '-frontend' ), |
|
| 105 | + 'path' => $this->asset_api->get_block_asset_build_path($this->block_name . '-frontend'), |
|
| 106 | 106 | 'dependencies' => [], |
| 107 | 107 | ]; |
| 108 | - return $key ? $script[ $key ] : $script; |
|
| 108 | + return $key ? $script[$key] : $script; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -115,15 +115,15 @@ discard block |
||
| 115 | 115 | * Note, this will be empty in the editor context when the block is |
| 116 | 116 | * not in the post content on editor load. |
| 117 | 117 | */ |
| 118 | - protected function enqueue_data( array $attributes = [] ) { |
|
| 119 | - if ( is_cart() || is_checkout() ) { |
|
| 118 | + protected function enqueue_data(array $attributes = []) { |
|
| 119 | + if (is_cart() || is_checkout()) { |
|
| 120 | 120 | return; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - parent::enqueue_data( $attributes ); |
|
| 123 | + parent::enqueue_data($attributes); |
|
| 124 | 124 | |
| 125 | 125 | // Hydrate the following data depending on admin or frontend context. |
| 126 | - if ( ! is_admin() && ! WC()->is_rest_api_request() ) { |
|
| 126 | + if (!is_admin() && !WC()->is_rest_api_request()) { |
|
| 127 | 127 | $label_info = $this->get_tax_label(); |
| 128 | 128 | |
| 129 | 129 | $this->tax_label = $label_info['tax_label']; |
@@ -139,41 +139,41 @@ discard block |
||
| 139 | 139 | |
| 140 | 140 | $this->asset_data_registry->add( |
| 141 | 141 | 'cartTotals', |
| 142 | - isset( $cart_payload['totals'] ) ? $cart_payload['totals'] : null, |
|
| 142 | + isset($cart_payload['totals']) ? $cart_payload['totals'] : null, |
|
| 143 | 143 | null |
| 144 | 144 | ); |
| 145 | 145 | |
| 146 | 146 | $this->asset_data_registry->add( |
| 147 | 147 | 'cartItemsCount', |
| 148 | - isset( $cart_payload['items_count'] ) ? $cart_payload['items_count'] : null, |
|
| 148 | + isset($cart_payload['items_count']) ? $cart_payload['items_count'] : null, |
|
| 149 | 149 | null |
| 150 | 150 | ); |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - $script_data = $this->asset_api->get_script_data( 'build/mini-cart-component-frontend.js' ); |
|
| 153 | + $script_data = $this->asset_api->get_script_data('build/mini-cart-component-frontend.js'); |
|
| 154 | 154 | |
| 155 | - $num_dependencies = count( $script_data['dependencies'] ); |
|
| 155 | + $num_dependencies = count($script_data['dependencies']); |
|
| 156 | 156 | $wp_scripts = wp_scripts(); |
| 157 | 157 | |
| 158 | - for ( $i = 0; $i < $num_dependencies; $i++ ) { |
|
| 159 | - $dependency = $script_data['dependencies'][ $i ]; |
|
| 158 | + for ($i = 0; $i < $num_dependencies; $i++) { |
|
| 159 | + $dependency = $script_data['dependencies'][$i]; |
|
| 160 | 160 | |
| 161 | - foreach ( $wp_scripts->registered as $script ) { |
|
| 162 | - if ( $script->handle === $dependency ) { |
|
| 163 | - $this->append_script_and_deps_src( $script ); |
|
| 161 | + foreach ($wp_scripts->registered as $script) { |
|
| 162 | + if ($script->handle === $dependency) { |
|
| 163 | + $this->append_script_and_deps_src($script); |
|
| 164 | 164 | break; |
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - $payment_method_registry = Package::container()->get( PaymentMethodRegistry::class ); |
|
| 169 | + $payment_method_registry = Package::container()->get(PaymentMethodRegistry::class); |
|
| 170 | 170 | $payment_methods = $payment_method_registry->get_all_active_payment_method_script_dependencies(); |
| 171 | 171 | |
| 172 | - foreach ( $payment_methods as $payment_method ) { |
|
| 173 | - $payment_method_script = $this->get_script_from_handle( $payment_method ); |
|
| 172 | + foreach ($payment_methods as $payment_method) { |
|
| 173 | + $payment_method_script = $this->get_script_from_handle($payment_method); |
|
| 174 | 174 | |
| 175 | - if ( ! is_null( $payment_method_script ) ) { |
|
| 176 | - $this->append_script_and_deps_src( $payment_method_script ); |
|
| 175 | + if (!is_null($payment_method_script)) { |
|
| 176 | + $this->append_script_and_deps_src($payment_method_script); |
|
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | |
@@ -198,22 +198,22 @@ discard block |
||
| 198 | 198 | $template_part_edit_uri = ''; |
| 199 | 199 | |
| 200 | 200 | if ( |
| 201 | - current_user_can( 'edit_theme_options' ) && |
|
| 201 | + current_user_can('edit_theme_options') && |
|
| 202 | 202 | wc_current_theme_is_fse_theme() |
| 203 | 203 | ) { |
| 204 | - $theme_slug = BlockTemplateUtils::theme_has_template_part( 'mini-cart' ) ? wp_get_theme()->get_stylesheet() : BlockTemplateUtils::PLUGIN_SLUG; |
|
| 205 | - $site_editor_uri = admin_url( 'site-editor.php' ); |
|
| 204 | + $theme_slug = BlockTemplateUtils::theme_has_template_part('mini-cart') ? wp_get_theme()->get_stylesheet() : BlockTemplateUtils::PLUGIN_SLUG; |
|
| 205 | + $site_editor_uri = admin_url('site-editor.php'); |
|
| 206 | 206 | |
| 207 | - if ( version_compare( get_bloginfo( 'version' ), '5.9', '<' ) ) { |
|
| 207 | + if (version_compare(get_bloginfo('version'), '5.9', '<')) { |
|
| 208 | 208 | $site_editor_uri = add_query_arg( |
| 209 | - array( 'page' => 'gutenberg-edit-site' ), |
|
| 210 | - admin_url( 'themes.php' ) |
|
| 209 | + array('page' => 'gutenberg-edit-site'), |
|
| 210 | + admin_url('themes.php') |
|
| 211 | 211 | ); |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | $template_part_edit_uri = add_query_arg( |
| 215 | 215 | array( |
| 216 | - 'postId' => sprintf( '%s//%s', $theme_slug, 'mini-cart' ), |
|
| 216 | + 'postId' => sprintf('%s//%s', $theme_slug, 'mini-cart'), |
|
| 217 | 217 | 'postType' => 'wp_template_part', |
| 218 | 218 | ), |
| 219 | 219 | $site_editor_uri |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | /** |
| 230 | 230 | * Fires after cart block data is registered. |
| 231 | 231 | */ |
| 232 | - do_action( 'woocommerce_blocks_cart_enqueue_data' ); |
|
| 232 | + do_action('woocommerce_blocks_cart_enqueue_data'); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -239,10 +239,10 @@ discard block |
||
| 239 | 239 | * |
| 240 | 240 | * @return \_WP_Dependency|null Object containing the script data if found, or null. |
| 241 | 241 | */ |
| 242 | - protected function get_script_from_handle( $handle ) { |
|
| 242 | + protected function get_script_from_handle($handle) { |
|
| 243 | 243 | $wp_scripts = wp_scripts(); |
| 244 | - foreach ( $wp_scripts->registered as $script ) { |
|
| 245 | - if ( $script->handle === $handle ) { |
|
| 244 | + foreach ($wp_scripts->registered as $script) { |
|
| 245 | + if ($script->handle === $handle) { |
|
| 246 | 246 | return $script; |
| 247 | 247 | } |
| 248 | 248 | } |
@@ -254,34 +254,34 @@ discard block |
||
| 254 | 254 | * |
| 255 | 255 | * @param \_WP_Dependency $script Object containing script data. |
| 256 | 256 | */ |
| 257 | - protected function append_script_and_deps_src( $script ) { |
|
| 257 | + protected function append_script_and_deps_src($script) { |
|
| 258 | 258 | $wp_scripts = wp_scripts(); |
| 259 | 259 | |
| 260 | 260 | // This script and its dependencies have already been appended. |
| 261 | - if ( ! $script || array_key_exists( $script->handle, $this->scripts_to_lazy_load ) ) { |
|
| 261 | + if (!$script || array_key_exists($script->handle, $this->scripts_to_lazy_load)) { |
|
| 262 | 262 | return; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - if ( count( $script->deps ) ) { |
|
| 266 | - foreach ( $script->deps as $dep ) { |
|
| 267 | - if ( ! array_key_exists( $dep, $this->scripts_to_lazy_load ) ) { |
|
| 268 | - $dep_script = $this->get_script_from_handle( $dep ); |
|
| 265 | + if (count($script->deps)) { |
|
| 266 | + foreach ($script->deps as $dep) { |
|
| 267 | + if (!array_key_exists($dep, $this->scripts_to_lazy_load)) { |
|
| 268 | + $dep_script = $this->get_script_from_handle($dep); |
|
| 269 | 269 | |
| 270 | - if ( ! is_null( $dep_script ) ) { |
|
| 271 | - $this->append_script_and_deps_src( $dep_script ); |
|
| 270 | + if (!is_null($dep_script)) { |
|
| 271 | + $this->append_script_and_deps_src($dep_script); |
|
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | 275 | } |
| 276 | - if ( ! $script->src ) { |
|
| 276 | + if (!$script->src) { |
|
| 277 | 277 | return; |
| 278 | 278 | } |
| 279 | - $this->scripts_to_lazy_load[ $script->handle ] = array( |
|
| 279 | + $this->scripts_to_lazy_load[$script->handle] = array( |
|
| 280 | 280 | 'src' => $script->src, |
| 281 | 281 | 'version' => $script->ver, |
| 282 | - 'before' => $wp_scripts->print_inline_script( $script->handle, 'before', false ), |
|
| 283 | - 'after' => $wp_scripts->print_inline_script( $script->handle, 'after', false ), |
|
| 284 | - 'translations' => $wp_scripts->print_translations( $script->handle, false ), |
|
| 282 | + 'before' => $wp_scripts->print_inline_script($script->handle, 'before', false), |
|
| 283 | + 'after' => $wp_scripts->print_inline_script($script->handle, 'after', false), |
|
| 284 | + 'translations' => $wp_scripts->print_translations($script->handle, false), |
|
| 285 | 285 | ); |
| 286 | 286 | } |
| 287 | 287 | |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | $cart = $cart_controller->get_cart_instance(); |
| 296 | 296 | $cart_contents_total = $cart->get_subtotal(); |
| 297 | 297 | |
| 298 | - return ( ! empty( $this->tax_label ) && 0 !== $cart_contents_total ) ? ( "<small class='wc-block-mini-cart__tax-label'>" . esc_html( $this->tax_label ) . '</small>' ) : ''; |
|
| 298 | + return (!empty($this->tax_label) && 0 !== $cart_contents_total) ? ("<small class='wc-block-mini-cart__tax-label'>" . esc_html($this->tax_label) . '</small>') : ''; |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | /** |
@@ -306,8 +306,8 @@ discard block |
||
| 306 | 306 | * |
| 307 | 307 | * @return string Rendered block type output. |
| 308 | 308 | */ |
| 309 | - protected function render( $attributes, $content ) { |
|
| 310 | - return $content . $this->get_markup( $attributes ); |
|
| 309 | + protected function render($attributes, $content) { |
|
| 310 | + return $content . $this->get_markup($attributes); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | /** |
@@ -317,8 +317,8 @@ discard block |
||
| 317 | 317 | * |
| 318 | 318 | * @return string The HTML markup. |
| 319 | 319 | */ |
| 320 | - protected function get_markup( $attributes ) { |
|
| 321 | - if ( is_admin() || WC()->is_rest_api_request() ) { |
|
| 320 | + protected function get_markup($attributes) { |
|
| 321 | + if (is_admin() || WC()->is_rest_api_request()) { |
|
| 322 | 322 | // In the editor we will display the placeholder, so no need to load |
| 323 | 323 | // real cart data and to print the markup. |
| 324 | 324 | return ''; |
@@ -330,12 +330,12 @@ discard block |
||
| 330 | 330 | $cart_contents = $cart->get_cart(); |
| 331 | 331 | $cart_contents_total = $cart->get_subtotal(); |
| 332 | 332 | |
| 333 | - if ( $cart->display_prices_including_tax() ) { |
|
| 333 | + if ($cart->display_prices_including_tax()) { |
|
| 334 | 334 | $cart_contents_total += $cart->get_subtotal_tax(); |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - $classes_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, array( 'text_color', 'background_color', 'font_size', 'font_family' ) ); |
|
| 338 | - $wrapper_classes = sprintf( 'wc-block-mini-cart wp-block-woocommerce-mini-cart %s', $classes_styles['classes'] ); |
|
| 337 | + $classes_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes($attributes, array('text_color', 'background_color', 'font_size', 'font_family')); |
|
| 338 | + $wrapper_classes = sprintf('wc-block-mini-cart wp-block-woocommerce-mini-cart %s', $classes_styles['classes']); |
|
| 339 | 339 | $wrapper_styles = $classes_styles['styles']; |
| 340 | 340 | |
| 341 | 341 | $aria_label = sprintf( |
@@ -347,47 +347,47 @@ discard block |
||
| 347 | 347 | 'woocommerce' |
| 348 | 348 | ), |
| 349 | 349 | $cart_contents_count, |
| 350 | - wp_strip_all_tags( wc_price( $cart_contents_total ) ) |
|
| 350 | + wp_strip_all_tags(wc_price($cart_contents_total)) |
|
| 351 | 351 | ); |
| 352 | - $icon = '<svg class="wc-block-mini-cart__icon" width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"> |
|
| 352 | + $icon = '<svg class="wc-block-mini-cart__icon" width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"> |
|
| 353 | 353 | <path fill-rule="evenodd" clip-rule="evenodd" d="M7.84614 18.2769C7.89712 18.2769 7.93845 18.2356 7.93845 18.1846C7.93845 18.1336 7.89712 18.0923 7.84614 18.0923C7.79516 18.0923 7.75384 18.1336 7.75384 18.1846C7.75384 18.2356 7.79516 18.2769 7.84614 18.2769ZM6.03076 18.1846C6.03076 17.182 6.84353 16.3692 7.84614 16.3692C8.84875 16.3692 9.66152 17.182 9.66152 18.1846C9.66152 19.1872 8.84875 20 7.84614 20C6.84353 20 6.03076 19.1872 6.03076 18.1846Z" fill="currentColor"/> |
| 354 | 354 | <path fill-rule="evenodd" clip-rule="evenodd" d="M17.3231 18.2769C17.3741 18.2769 17.4154 18.2356 17.4154 18.1846C17.4154 18.1336 17.3741 18.0923 17.3231 18.0923C17.2721 18.0923 17.2308 18.1336 17.2308 18.1846C17.2308 18.2356 17.2721 18.2769 17.3231 18.2769ZM15.5077 18.1846C15.5077 17.182 16.3205 16.3692 17.3231 16.3692C18.3257 16.3692 19.1385 17.182 19.1385 18.1846C19.1385 19.1872 18.3257 20 17.3231 20C16.3205 20 15.5077 19.1872 15.5077 18.1846Z" fill="currentColor"/> |
| 355 | 355 | <path fill-rule="evenodd" clip-rule="evenodd" d="M20.0631 9.53835L19.4662 12.6685L19.4648 12.6757L19.4648 12.6757C19.3424 13.2919 19.0072 13.8454 18.5178 14.2394C18.031 14.6312 17.4226 14.8404 16.798 14.8308H8.44017C7.81556 14.8404 7.20714 14.6312 6.72038 14.2394C6.2312 13.8456 5.89605 13.2924 5.77352 12.6765L5.77335 12.6757L4.33477 5.48814C4.3286 5.46282 4.32345 5.43711 4.31934 5.41104L3.61815 1.90768H0.953842C0.42705 1.90768 0 1.48063 0 0.953842C0 0.42705 0.42705 0 0.953842 0H4.4C4.85462 0 5.24607 0.320858 5.33529 0.766644L6.04403 4.30769H12.785C13.0114 4.99157 13.3319 5.63258 13.7312 6.21538H6.42585L7.64421 12.3026L7.64449 12.304C7.67966 12.4811 7.77599 12.6402 7.91662 12.7534C8.05725 12.8666 8.23322 12.9267 8.41372 12.9233L8.432 12.9231H16.8062L16.8244 12.9233C17.0049 12.9267 17.1809 12.8666 17.3215 12.7534C17.4614 12.6408 17.5575 12.4828 17.5931 12.3068L17.5937 12.304L18.1649 9.30867C18.762 9.45873 19.387 9.53842 20.0307 9.53842C20.0415 9.53842 20.0523 9.5384 20.0631 9.53835Z" fill="currentColor"/> |
| 356 | 356 | </svg>'; |
| 357 | - $button_html = '<span class="wc-block-mini-cart__amount">' . esc_html( wp_strip_all_tags( wc_price( $cart_contents_total ) ) ) . '</span> |
|
| 357 | + $button_html = '<span class="wc-block-mini-cart__amount">' . esc_html(wp_strip_all_tags(wc_price($cart_contents_total))) . '</span> |
|
| 358 | 358 | ' . $this->get_include_tax_label_markup() . ' |
| 359 | 359 | <span class="wc-block-mini-cart__quantity-badge"> |
| 360 | 360 | ' . $icon . ' |
| 361 | 361 | <span class="wc-block-mini-cart__badge">' . $cart_contents_count . '</span> |
| 362 | 362 | </span>'; |
| 363 | 363 | |
| 364 | - if ( is_cart() || is_checkout() ) { |
|
| 364 | + if (is_cart() || is_checkout()) { |
|
| 365 | 365 | // It is not necessary to load the Mini Cart Block on Cart and Checkout page. |
| 366 | 366 | return '<div class="' . $wrapper_classes . '" style="visibility:hidden" aria-hidden="true"> |
| 367 | - <button class="wc-block-mini-cart__button" aria-label="' . esc_attr( $aria_label ) . '" disabled>' . $button_html . '</button> |
|
| 367 | + <button class="wc-block-mini-cart__button" aria-label="' . esc_attr($aria_label) . '" disabled>' . $button_html . '</button> |
|
| 368 | 368 | </div>'; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | $template_part_contents = ''; |
| 372 | 372 | |
| 373 | 373 | // Determine if we need to load the template part from the theme, or WooCommerce in that order. |
| 374 | - $theme_has_mini_cart = BlockTemplateUtils::theme_has_template_part( 'mini-cart' ); |
|
| 374 | + $theme_has_mini_cart = BlockTemplateUtils::theme_has_template_part('mini-cart'); |
|
| 375 | 375 | $template_slug_to_load = $theme_has_mini_cart ? get_stylesheet() : BlockTemplateUtils::PLUGIN_SLUG; |
| 376 | - $template_part = BlockTemplateUtils::get_block_template( $template_slug_to_load . '//mini-cart', 'wp_template_part' ); |
|
| 376 | + $template_part = BlockTemplateUtils::get_block_template($template_slug_to_load . '//mini-cart', 'wp_template_part'); |
|
| 377 | 377 | |
| 378 | - if ( $template_part && ! empty( $template_part->content ) ) { |
|
| 379 | - $template_part_contents = do_blocks( $template_part->content ); |
|
| 378 | + if ($template_part && !empty($template_part->content)) { |
|
| 379 | + $template_part_contents = do_blocks($template_part->content); |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | - if ( '' === $template_part_contents ) { |
|
| 382 | + if ('' === $template_part_contents) { |
|
| 383 | 383 | $template_part_contents = do_blocks( |
| 384 | 384 | // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
| 385 | - file_get_contents( Package::get_path() . 'templates/' . BlockTemplateUtils::DIRECTORY_NAMES['TEMPLATE_PARTS'] . '/mini-cart.html' ) |
|
| 385 | + file_get_contents(Package::get_path() . 'templates/' . BlockTemplateUtils::DIRECTORY_NAMES['TEMPLATE_PARTS'] . '/mini-cart.html') |
|
| 386 | 386 | ); |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | return '<div class="' . $wrapper_classes . '" style="' . $wrapper_styles . '"> |
| 390 | - <button class="wc-block-mini-cart__button" aria-label="' . esc_attr( $aria_label ) . '">' . $button_html . '</button> |
|
| 390 | + <button class="wc-block-mini-cart__button" aria-label="' . esc_attr($aria_label) . '">' . $button_html . '</button> |
|
| 391 | 391 | <div class="wc-block-mini-cart__drawer is-loading is-mobile wc-block-components-drawer__screen-overlay wc-block-components-drawer__screen-overlay--is-hidden" aria-hidden="true"> |
| 392 | 392 | <div class="components-modal__frame wc-block-components-drawer"> |
| 393 | 393 | <div class="components-modal__content"> |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | <div class="components-modal__header-heading-container"></div> |
| 396 | 396 | </div> |
| 397 | 397 | <div class="wc-block-mini-cart__template-part">' |
| 398 | - . wp_kses_post( $template_part_contents ) . |
|
| 398 | + . wp_kses_post($template_part_contents) . |
|
| 399 | 399 | '</div> |
| 400 | 400 | </div> |
| 401 | 401 | </div> |
@@ -422,8 +422,8 @@ discard block |
||
| 422 | 422 | protected function get_tax_label() { |
| 423 | 423 | $cart = WC()->cart; |
| 424 | 424 | |
| 425 | - if ( $cart->display_prices_including_tax() ) { |
|
| 426 | - if ( ! wc_prices_include_tax() ) { |
|
| 425 | + if ($cart->display_prices_including_tax()) { |
|
| 426 | + if (!wc_prices_include_tax()) { |
|
| 427 | 427 | $tax_label = WC()->countries->inc_tax_or_vat(); |
| 428 | 428 | $display_cart_prices_including_tax = true; |
| 429 | 429 | return array( |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | ); |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | - if ( wc_prices_include_tax() ) { |
|
| 440 | + if (wc_prices_include_tax()) { |
|
| 441 | 441 | $tax_label = WC()->countries->ex_tax_or_vat(); |
| 442 | 442 | return array( |
| 443 | 443 | 'tax_label' => $tax_label, |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | * @return object; |
| 458 | 458 | */ |
| 459 | 459 | protected function get_cart_payload() { |
| 460 | - return WC()->api->get_endpoint_data( '/wc/store/cart' ); |
|
| 460 | + return WC()->api->get_endpoint_data('/wc/store/cart'); |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | /** |
@@ -467,20 +467,20 @@ discard block |
||
| 467 | 467 | $wp_scripts = wp_scripts(); |
| 468 | 468 | $translations = array(); |
| 469 | 469 | |
| 470 | - $chunks = $this->get_chunks_paths( $this->chunks_folder ); |
|
| 471 | - $vendor_chunks = $this->get_chunks_paths( 'vendors--mini-cart-contents-block' ); |
|
| 472 | - $shared_chunks = [ 'cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend' ]; |
|
| 470 | + $chunks = $this->get_chunks_paths($this->chunks_folder); |
|
| 471 | + $vendor_chunks = $this->get_chunks_paths('vendors--mini-cart-contents-block'); |
|
| 472 | + $shared_chunks = ['cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend']; |
|
| 473 | 473 | |
| 474 | - foreach ( array_merge( $chunks, $vendor_chunks, $shared_chunks ) as $chunk ) { |
|
| 474 | + foreach (array_merge($chunks, $vendor_chunks, $shared_chunks) as $chunk) { |
|
| 475 | 475 | $handle = 'wc-blocks-' . $chunk . '-chunk'; |
| 476 | - $this->asset_api->register_script( $handle, $this->asset_api->get_block_asset_build_path( $chunk ), [], true ); |
|
| 477 | - $translations[] = $wp_scripts->print_translations( $handle, false ); |
|
| 478 | - wp_deregister_script( $handle ); |
|
| 476 | + $this->asset_api->register_script($handle, $this->asset_api->get_block_asset_build_path($chunk), [], true); |
|
| 477 | + $translations[] = $wp_scripts->print_translations($handle, false); |
|
| 478 | + wp_deregister_script($handle); |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | - $translations = array_filter( $translations ); |
|
| 481 | + $translations = array_filter($translations); |
|
| 482 | 482 | |
| 483 | - return implode( '', $translations ); |
|
| 483 | + return implode('', $translations); |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | /** |
@@ -490,9 +490,9 @@ discard block |
||
| 490 | 490 | register_block_pattern( |
| 491 | 491 | 'woocommerce/mini-cart-empty-cart-message', |
| 492 | 492 | array( |
| 493 | - 'title' => __( 'Mini Cart Empty Cart Message', 'woocommerce' ), |
|
| 493 | + 'title' => __('Mini Cart Empty Cart Message', 'woocommerce'), |
|
| 494 | 494 | 'inserter' => false, |
| 495 | - 'content' => '<!-- wp:paragraph {"align":"center"} --><p class="has-text-align-center"><strong>' . __( 'Your cart is currently empty!', 'woocommerce' ) . '</strong></p><!-- /wp:paragraph -->', |
|
| 495 | + 'content' => '<!-- wp:paragraph {"align":"center"} --><p class="has-text-align-center"><strong>' . __('Your cart is currently empty!', 'woocommerce') . '</strong></p><!-- /wp:paragraph -->', |
|
| 496 | 496 | ) |
| 497 | 497 | ); |
| 498 | 498 | } |
@@ -5,98 +5,98 @@ |
||
| 5 | 5 | * FeaturedCategory class. |
| 6 | 6 | */ |
| 7 | 7 | class FeaturedCategory extends FeaturedItem { |
| 8 | - /** |
|
| 9 | - * Block name. |
|
| 10 | - * |
|
| 11 | - * @var string |
|
| 12 | - */ |
|
| 13 | - protected $block_name = 'featured-category'; |
|
| 8 | + /** |
|
| 9 | + * Block name. |
|
| 10 | + * |
|
| 11 | + * @var string |
|
| 12 | + */ |
|
| 13 | + protected $block_name = 'featured-category'; |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Get block attributes. |
|
| 17 | - * |
|
| 18 | - * @return array |
|
| 19 | - */ |
|
| 20 | - protected function get_block_type_attributes() { |
|
| 21 | - return array_merge( |
|
| 22 | - parent::get_block_type_attributes(), |
|
| 23 | - array( |
|
| 24 | - 'textColor' => $this->get_schema_string(), |
|
| 25 | - 'fontSize' => $this->get_schema_string(), |
|
| 26 | - 'lineHeight' => $this->get_schema_string(), |
|
| 27 | - 'style' => array( 'type' => 'object' ), |
|
| 28 | - ) |
|
| 29 | - ); |
|
| 30 | - } |
|
| 15 | + /** |
|
| 16 | + * Get block attributes. |
|
| 17 | + * |
|
| 18 | + * @return array |
|
| 19 | + */ |
|
| 20 | + protected function get_block_type_attributes() { |
|
| 21 | + return array_merge( |
|
| 22 | + parent::get_block_type_attributes(), |
|
| 23 | + array( |
|
| 24 | + 'textColor' => $this->get_schema_string(), |
|
| 25 | + 'fontSize' => $this->get_schema_string(), |
|
| 26 | + 'lineHeight' => $this->get_schema_string(), |
|
| 27 | + 'style' => array( 'type' => 'object' ), |
|
| 28 | + ) |
|
| 29 | + ); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Returns the featured category. |
|
| 34 | - * |
|
| 35 | - * @param array $attributes Block attributes. Default empty array. |
|
| 36 | - * @return \WP_Term|null |
|
| 37 | - */ |
|
| 38 | - protected function get_item( $attributes ) { |
|
| 39 | - $id = absint( $attributes['categoryId'] ?? 0 ); |
|
| 32 | + /** |
|
| 33 | + * Returns the featured category. |
|
| 34 | + * |
|
| 35 | + * @param array $attributes Block attributes. Default empty array. |
|
| 36 | + * @return \WP_Term|null |
|
| 37 | + */ |
|
| 38 | + protected function get_item( $attributes ) { |
|
| 39 | + $id = absint( $attributes['categoryId'] ?? 0 ); |
|
| 40 | 40 | |
| 41 | - $category = get_term( $id, 'product_cat' ); |
|
| 42 | - if ( ! $category || is_wp_error( $category ) ) { |
|
| 43 | - return null; |
|
| 44 | - } |
|
| 41 | + $category = get_term( $id, 'product_cat' ); |
|
| 42 | + if ( ! $category || is_wp_error( $category ) ) { |
|
| 43 | + return null; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - return $category; |
|
| 47 | - } |
|
| 46 | + return $category; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Returns the name of the featured category. |
|
| 51 | - * |
|
| 52 | - * @param \WP_Term $category Featured category. |
|
| 53 | - * @return string |
|
| 54 | - */ |
|
| 55 | - protected function get_item_title( $category ) { |
|
| 56 | - return $category->name; |
|
| 57 | - } |
|
| 49 | + /** |
|
| 50 | + * Returns the name of the featured category. |
|
| 51 | + * |
|
| 52 | + * @param \WP_Term $category Featured category. |
|
| 53 | + * @return string |
|
| 54 | + */ |
|
| 55 | + protected function get_item_title( $category ) { |
|
| 56 | + return $category->name; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Returns the featured category image URL. |
|
| 61 | - * |
|
| 62 | - * @param \WP_Term $category Term object. |
|
| 63 | - * @param string $size Image size, defaults to 'full'. |
|
| 64 | - * @return string |
|
| 65 | - */ |
|
| 66 | - protected function get_item_image( $category, $size = 'full' ) { |
|
| 67 | - $image = ''; |
|
| 68 | - $image_id = get_term_meta( $category->term_id, 'thumbnail_id', true ); |
|
| 59 | + /** |
|
| 60 | + * Returns the featured category image URL. |
|
| 61 | + * |
|
| 62 | + * @param \WP_Term $category Term object. |
|
| 63 | + * @param string $size Image size, defaults to 'full'. |
|
| 64 | + * @return string |
|
| 65 | + */ |
|
| 66 | + protected function get_item_image( $category, $size = 'full' ) { |
|
| 67 | + $image = ''; |
|
| 68 | + $image_id = get_term_meta( $category->term_id, 'thumbnail_id', true ); |
|
| 69 | 69 | |
| 70 | - if ( $image_id ) { |
|
| 71 | - $image = wp_get_attachment_image_url( $image_id, $size ); |
|
| 72 | - } |
|
| 70 | + if ( $image_id ) { |
|
| 71 | + $image = wp_get_attachment_image_url( $image_id, $size ); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - return $image; |
|
| 75 | - } |
|
| 74 | + return $image; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Renders the featured category attributes. |
|
| 79 | - * |
|
| 80 | - * @param \WP_Term $category Term object. |
|
| 81 | - * @param array $attributes Block attributes. Default empty array. |
|
| 82 | - * @return string |
|
| 83 | - */ |
|
| 84 | - protected function render_attributes( $category, $attributes ) { |
|
| 85 | - $title = sprintf( |
|
| 86 | - '<h2 class="wc-block-featured-category__title">%s</h2>', |
|
| 87 | - wp_kses_post( $category->name ) |
|
| 88 | - ); |
|
| 77 | + /** |
|
| 78 | + * Renders the featured category attributes. |
|
| 79 | + * |
|
| 80 | + * @param \WP_Term $category Term object. |
|
| 81 | + * @param array $attributes Block attributes. Default empty array. |
|
| 82 | + * @return string |
|
| 83 | + */ |
|
| 84 | + protected function render_attributes( $category, $attributes ) { |
|
| 85 | + $title = sprintf( |
|
| 86 | + '<h2 class="wc-block-featured-category__title">%s</h2>', |
|
| 87 | + wp_kses_post( $category->name ) |
|
| 88 | + ); |
|
| 89 | 89 | |
| 90 | - $desc_str = sprintf( |
|
| 91 | - '<div class="wc-block-featured-category__description">%s</div>', |
|
| 92 | - wc_format_content( wp_kses_post( $category->description ) ) |
|
| 93 | - ); |
|
| 90 | + $desc_str = sprintf( |
|
| 91 | + '<div class="wc-block-featured-category__description">%s</div>', |
|
| 92 | + wc_format_content( wp_kses_post( $category->description ) ) |
|
| 93 | + ); |
|
| 94 | 94 | |
| 95 | - $output = $title; |
|
| 96 | - if ( $attributes['showDesc'] ) { |
|
| 97 | - $output .= $desc_str; |
|
| 98 | - } |
|
| 95 | + $output = $title; |
|
| 96 | + if ( $attributes['showDesc'] ) { |
|
| 97 | + $output .= $desc_str; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - return $output; |
|
| 101 | - } |
|
| 100 | + return $output; |
|
| 101 | + } |
|
| 102 | 102 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | 'textColor' => $this->get_schema_string(), |
| 25 | 25 | 'fontSize' => $this->get_schema_string(), |
| 26 | 26 | 'lineHeight' => $this->get_schema_string(), |
| 27 | - 'style' => array( 'type' => 'object' ), |
|
| 27 | + 'style' => array('type' => 'object'), |
|
| 28 | 28 | ) |
| 29 | 29 | ); |
| 30 | 30 | } |
@@ -35,11 +35,11 @@ discard block |
||
| 35 | 35 | * @param array $attributes Block attributes. Default empty array. |
| 36 | 36 | * @return \WP_Term|null |
| 37 | 37 | */ |
| 38 | - protected function get_item( $attributes ) { |
|
| 39 | - $id = absint( $attributes['categoryId'] ?? 0 ); |
|
| 38 | + protected function get_item($attributes) { |
|
| 39 | + $id = absint($attributes['categoryId'] ?? 0); |
|
| 40 | 40 | |
| 41 | - $category = get_term( $id, 'product_cat' ); |
|
| 42 | - if ( ! $category || is_wp_error( $category ) ) { |
|
| 41 | + $category = get_term($id, 'product_cat'); |
|
| 42 | + if (!$category || is_wp_error($category)) { |
|
| 43 | 43 | return null; |
| 44 | 44 | } |
| 45 | 45 | |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @param \WP_Term $category Featured category. |
| 53 | 53 | * @return string |
| 54 | 54 | */ |
| 55 | - protected function get_item_title( $category ) { |
|
| 55 | + protected function get_item_title($category) { |
|
| 56 | 56 | return $category->name; |
| 57 | 57 | } |
| 58 | 58 | |
@@ -63,12 +63,12 @@ discard block |
||
| 63 | 63 | * @param string $size Image size, defaults to 'full'. |
| 64 | 64 | * @return string |
| 65 | 65 | */ |
| 66 | - protected function get_item_image( $category, $size = 'full' ) { |
|
| 66 | + protected function get_item_image($category, $size = 'full') { |
|
| 67 | 67 | $image = ''; |
| 68 | - $image_id = get_term_meta( $category->term_id, 'thumbnail_id', true ); |
|
| 68 | + $image_id = get_term_meta($category->term_id, 'thumbnail_id', true); |
|
| 69 | 69 | |
| 70 | - if ( $image_id ) { |
|
| 71 | - $image = wp_get_attachment_image_url( $image_id, $size ); |
|
| 70 | + if ($image_id) { |
|
| 71 | + $image = wp_get_attachment_image_url($image_id, $size); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | return $image; |
@@ -81,19 +81,19 @@ discard block |
||
| 81 | 81 | * @param array $attributes Block attributes. Default empty array. |
| 82 | 82 | * @return string |
| 83 | 83 | */ |
| 84 | - protected function render_attributes( $category, $attributes ) { |
|
| 84 | + protected function render_attributes($category, $attributes) { |
|
| 85 | 85 | $title = sprintf( |
| 86 | 86 | '<h2 class="wc-block-featured-category__title">%s</h2>', |
| 87 | - wp_kses_post( $category->name ) |
|
| 87 | + wp_kses_post($category->name) |
|
| 88 | 88 | ); |
| 89 | 89 | |
| 90 | 90 | $desc_str = sprintf( |
| 91 | 91 | '<div class="wc-block-featured-category__description">%s</div>', |
| 92 | - wc_format_content( wp_kses_post( $category->description ) ) |
|
| 92 | + wc_format_content(wp_kses_post($category->description)) |
|
| 93 | 93 | ); |
| 94 | 94 | |
| 95 | 95 | $output = $title; |
| 96 | - if ( $attributes['showDesc'] ) { |
|
| 96 | + if ($attributes['showDesc']) { |
|
| 97 | 97 | $output .= $desc_str; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -5,33 +5,33 @@ |
||
| 5 | 5 | * ProductCategory class. |
| 6 | 6 | */ |
| 7 | 7 | class ProductCategory extends AbstractProductGrid { |
| 8 | - /** |
|
| 9 | - * Block name. |
|
| 10 | - * |
|
| 11 | - * @var string |
|
| 12 | - */ |
|
| 13 | - protected $block_name = 'product-category'; |
|
| 8 | + /** |
|
| 9 | + * Block name. |
|
| 10 | + * |
|
| 11 | + * @var string |
|
| 12 | + */ |
|
| 13 | + protected $block_name = 'product-category'; |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Set args specific to this block |
|
| 17 | - * |
|
| 18 | - * @param array $query_args Query args. |
|
| 19 | - */ |
|
| 20 | - protected function set_block_query_args( &$query_args ) {} |
|
| 15 | + /** |
|
| 16 | + * Set args specific to this block |
|
| 17 | + * |
|
| 18 | + * @param array $query_args Query args. |
|
| 19 | + */ |
|
| 20 | + protected function set_block_query_args( &$query_args ) {} |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Get block attributes. |
|
| 24 | - * |
|
| 25 | - * @return array |
|
| 26 | - */ |
|
| 27 | - protected function get_block_type_attributes() { |
|
| 28 | - return array_merge( |
|
| 29 | - parent::get_block_type_attributes(), |
|
| 30 | - array( |
|
| 31 | - 'className' => $this->get_schema_string(), |
|
| 32 | - 'orderby' => $this->get_schema_orderby(), |
|
| 33 | - 'editMode' => $this->get_schema_boolean( true ), |
|
| 34 | - ) |
|
| 35 | - ); |
|
| 36 | - } |
|
| 22 | + /** |
|
| 23 | + * Get block attributes. |
|
| 24 | + * |
|
| 25 | + * @return array |
|
| 26 | + */ |
|
| 27 | + protected function get_block_type_attributes() { |
|
| 28 | + return array_merge( |
|
| 29 | + parent::get_block_type_attributes(), |
|
| 30 | + array( |
|
| 31 | + 'className' => $this->get_schema_string(), |
|
| 32 | + 'orderby' => $this->get_schema_orderby(), |
|
| 33 | + 'editMode' => $this->get_schema_boolean( true ), |
|
| 34 | + ) |
|
| 35 | + ); |
|
| 36 | + } |
|
| 37 | 37 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * |
| 18 | 18 | * @param array $query_args Query args. |
| 19 | 19 | */ |
| 20 | - protected function set_block_query_args( &$query_args ) {} |
|
| 20 | + protected function set_block_query_args(&$query_args) {} |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * Get block attributes. |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | array( |
| 31 | 31 | 'className' => $this->get_schema_string(), |
| 32 | 32 | 'orderby' => $this->get_schema_orderby(), |
| 33 | - 'editMode' => $this->get_schema_boolean( true ), |
|
| 33 | + 'editMode' => $this->get_schema_boolean(true), |
|
| 34 | 34 | ) |
| 35 | 35 | ); |
| 36 | 36 | } |
@@ -5,10 +5,10 @@ |
||
| 5 | 5 | * ActiveFilters class. |
| 6 | 6 | */ |
| 7 | 7 | class ActiveFilters extends AbstractBlock { |
| 8 | - /** |
|
| 9 | - * Block name. |
|
| 10 | - * |
|
| 11 | - * @var string |
|
| 12 | - */ |
|
| 13 | - protected $block_name = 'active-filters'; |
|
| 8 | + /** |
|
| 9 | + * Block name. |
|
| 10 | + * |
|
| 11 | + * @var string |
|
| 12 | + */ |
|
| 13 | + protected $block_name = 'active-filters'; |
|
| 14 | 14 | } |
@@ -6,60 +6,60 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | class ProductTitle extends AbstractBlock { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * Block name. |
|
| 11 | - * |
|
| 12 | - * @var string |
|
| 13 | - */ |
|
| 14 | - protected $block_name = 'product-title'; |
|
| 9 | + /** |
|
| 10 | + * Block name. |
|
| 11 | + * |
|
| 12 | + * @var string |
|
| 13 | + */ |
|
| 14 | + protected $block_name = 'product-title'; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * API version name. |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - protected $api_version = '2'; |
|
| 16 | + /** |
|
| 17 | + * API version name. |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + protected $api_version = '2'; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Get block supports. Shared with the frontend. |
|
| 25 | - * IMPORTANT: If you change anything here, make sure to update the JS file too. |
|
| 26 | - * |
|
| 27 | - * @return array |
|
| 28 | - */ |
|
| 29 | - protected function get_block_type_supports() { |
|
| 30 | - return array( |
|
| 31 | - 'color' => |
|
| 32 | - array( |
|
| 33 | - 'gradients' => true, |
|
| 34 | - 'background' => true, |
|
| 35 | - 'link' => false, |
|
| 36 | - 'text' => true, |
|
| 37 | - '__experimentalSkipSerialization' => true, |
|
| 38 | - ), |
|
| 39 | - 'typography' => |
|
| 40 | - array( |
|
| 41 | - 'fontSize' => true, |
|
| 42 | - 'lineHeight' => true, |
|
| 43 | - '__experimentalFontWeight' => true, |
|
| 44 | - '__experimentalTextTransform' => true, |
|
| 45 | - '__experimentalFontFamily' => true, |
|
| 46 | - ), |
|
| 47 | - 'spacing' => |
|
| 48 | - array( |
|
| 49 | - 'margin' => true, |
|
| 50 | - '__experimentalSkipSerialization' => true, |
|
| 51 | - ), |
|
| 52 | - '__experimentalSelector' => '.wc-block-components-product-title', |
|
| 53 | - ); |
|
| 54 | - } |
|
| 23 | + /** |
|
| 24 | + * Get block supports. Shared with the frontend. |
|
| 25 | + * IMPORTANT: If you change anything here, make sure to update the JS file too. |
|
| 26 | + * |
|
| 27 | + * @return array |
|
| 28 | + */ |
|
| 29 | + protected function get_block_type_supports() { |
|
| 30 | + return array( |
|
| 31 | + 'color' => |
|
| 32 | + array( |
|
| 33 | + 'gradients' => true, |
|
| 34 | + 'background' => true, |
|
| 35 | + 'link' => false, |
|
| 36 | + 'text' => true, |
|
| 37 | + '__experimentalSkipSerialization' => true, |
|
| 38 | + ), |
|
| 39 | + 'typography' => |
|
| 40 | + array( |
|
| 41 | + 'fontSize' => true, |
|
| 42 | + 'lineHeight' => true, |
|
| 43 | + '__experimentalFontWeight' => true, |
|
| 44 | + '__experimentalTextTransform' => true, |
|
| 45 | + '__experimentalFontFamily' => true, |
|
| 46 | + ), |
|
| 47 | + 'spacing' => |
|
| 48 | + array( |
|
| 49 | + 'margin' => true, |
|
| 50 | + '__experimentalSkipSerialization' => true, |
|
| 51 | + ), |
|
| 52 | + '__experimentalSelector' => '.wc-block-components-product-title', |
|
| 53 | + ); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Register script and style assets for the block type before it is registered. |
|
| 58 | - * |
|
| 59 | - * This registers the scripts; it does not enqueue them. |
|
| 60 | - */ |
|
| 61 | - protected function register_block_type_assets() { |
|
| 62 | - parent::register_block_type_assets(); |
|
| 63 | - $this->register_chunk_translations( [ $this->block_name ] ); |
|
| 64 | - } |
|
| 56 | + /** |
|
| 57 | + * Register script and style assets for the block type before it is registered. |
|
| 58 | + * |
|
| 59 | + * This registers the scripts; it does not enqueue them. |
|
| 60 | + */ |
|
| 61 | + protected function register_block_type_assets() { |
|
| 62 | + parent::register_block_type_assets(); |
|
| 63 | + $this->register_chunk_translations( [ $this->block_name ] ); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -51,6 +51,6 @@ |
||
| 51 | 51 | */ |
| 52 | 52 | protected function register_block_type_assets() { |
| 53 | 53 | parent::register_block_type_assets(); |
| 54 | - $this->register_chunk_translations( [ $this->block_name ] ); |
|
| 54 | + $this->register_chunk_translations([$this->block_name]); |
|
| 55 | 55 | } |
| 56 | 56 | } |
@@ -8,333 +8,333 @@ |
||
| 8 | 8 | * FeaturedItem class. |
| 9 | 9 | */ |
| 10 | 10 | abstract class FeaturedItem extends AbstractDynamicBlock { |
| 11 | - /** |
|
| 12 | - * Block name. |
|
| 13 | - * |
|
| 14 | - * @var string |
|
| 15 | - */ |
|
| 16 | - protected $block_name; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * Default attribute values. |
|
| 20 | - * |
|
| 21 | - * @var array |
|
| 22 | - */ |
|
| 23 | - protected $defaults = array( |
|
| 24 | - 'align' => 'none', |
|
| 25 | - ); |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Global style enabled for this block. |
|
| 29 | - * |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $global_style_wrapper = array( |
|
| 33 | - 'background_color', |
|
| 34 | - 'border_color', |
|
| 35 | - 'border_radius', |
|
| 36 | - 'border_width', |
|
| 37 | - 'font_size', |
|
| 38 | - 'padding', |
|
| 39 | - 'text_color', |
|
| 40 | - ); |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Returns the featured item. |
|
| 44 | - * |
|
| 45 | - * @param array $attributes Block attributes. Default empty array. |
|
| 46 | - * @return \WP_Term|\WC_Product|null |
|
| 47 | - */ |
|
| 48 | - abstract protected function get_item( $attributes ); |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Returns the name of the featured item. |
|
| 52 | - * |
|
| 53 | - * @param \WP_Term|\WC_Product $item Item object. |
|
| 54 | - * @return string |
|
| 55 | - */ |
|
| 56 | - abstract protected function get_item_title( $item ); |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Returns the featured item image URL. |
|
| 60 | - * |
|
| 61 | - * @param \WP_Term|\WC_Product $item Item object. |
|
| 62 | - * @param string $size Image size, defaults to 'full'. |
|
| 63 | - * @return string |
|
| 64 | - */ |
|
| 65 | - abstract protected function get_item_image( $item, $size = 'full' ); |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Renders the featured item attributes. |
|
| 69 | - * |
|
| 70 | - * @param \WP_Term|\WC_Product $item Item object. |
|
| 71 | - * @param array $attributes Block attributes. Default empty array. |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - abstract protected function render_attributes( $item, $attributes ); |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Get the supports array for this block type. |
|
| 78 | - * |
|
| 79 | - * @return string[][]; |
|
| 80 | - * @see $this->register_block_type() |
|
| 81 | - */ |
|
| 82 | - protected function get_block_type_supports() { |
|
| 83 | - return array( |
|
| 84 | - 'color' => array( |
|
| 85 | - '__experimentalDuotone' => '.wc-block-' . $this->block_name . '__background-image', |
|
| 86 | - ), |
|
| 87 | - ); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Render the featured item block. |
|
| 92 | - * |
|
| 93 | - * @param array $attributes Block attributes. |
|
| 94 | - * @param string $content Block content. |
|
| 95 | - * @return string Rendered block type output. |
|
| 96 | - */ |
|
| 97 | - protected function render( $attributes, $content ) { |
|
| 98 | - $item = $this->get_item( $attributes ); |
|
| 99 | - if ( ! $item ) { |
|
| 100 | - return ''; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - $attributes = wp_parse_args( $attributes, $this->defaults ); |
|
| 104 | - |
|
| 105 | - $attributes['height'] = $attributes['height'] ?? wc_get_theme_support( 'featured_block::default_height', 500 ); |
|
| 106 | - |
|
| 107 | - $image_url = esc_url( $this->get_image_url( $attributes, $item ) ); |
|
| 108 | - |
|
| 109 | - $styles = $this->get_styles( $attributes ); |
|
| 110 | - $classes = $this->get_classes( $attributes ); |
|
| 111 | - |
|
| 112 | - $output = sprintf( '<div class="%1$s wp-block-woocommerce-%2$s" style="%3$s">', esc_attr( trim( $classes ) ), $this->block_name, esc_attr( $styles ) ); |
|
| 113 | - $output .= sprintf( '<div class="wc-block-%s__wrapper">', $this->block_name ); |
|
| 114 | - $output .= $this->render_overlay( $attributes ); |
|
| 115 | - |
|
| 116 | - if ( ! $attributes['isRepeated'] && ! $attributes['hasParallax'] ) { |
|
| 117 | - $output .= $this->render_image( $attributes, $item, $image_url ); |
|
| 118 | - } else { |
|
| 119 | - $output .= $this->render_bg_image( $attributes, $image_url ); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - $output .= $this->render_attributes( $item, $attributes ); |
|
| 123 | - $output .= sprintf( '<div class="wc-block-%s__link">%s</div>', $this->block_name, $content ); |
|
| 124 | - $output .= '</div>'; |
|
| 125 | - $output .= '</div>'; |
|
| 126 | - |
|
| 127 | - return $output; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Returns the url the item's image |
|
| 132 | - * |
|
| 133 | - * @param array $attributes Block attributes. Default empty array. |
|
| 134 | - * @param \WP_Term|\WC_Product $item Item object. |
|
| 135 | - * |
|
| 136 | - * @return string |
|
| 137 | - */ |
|
| 138 | - private function get_image_url( $attributes, $item ) { |
|
| 139 | - $image_size = 'large'; |
|
| 140 | - if ( 'none' !== $attributes['align'] || $attributes['height'] > 800 ) { |
|
| 141 | - $image_size = 'full'; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - if ( $attributes['mediaId'] ) { |
|
| 145 | - return wp_get_attachment_image_url( $attributes['mediaId'], $image_size ); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - return $this->get_item_image( $item, $image_size ); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Renders the featured image as a div background. |
|
| 153 | - * |
|
| 154 | - * @param array $attributes Block attributes. Default empty array. |
|
| 155 | - * @param string $image_url Item image url. |
|
| 156 | - * |
|
| 157 | - * @return string |
|
| 158 | - */ |
|
| 159 | - private function render_bg_image( $attributes, $image_url ) { |
|
| 160 | - $styles = $this->get_bg_styles( $attributes, $image_url ); |
|
| 161 | - |
|
| 162 | - $classes = [ "wc-block-{$this->block_name}__background-image" ]; |
|
| 163 | - |
|
| 164 | - if ( $attributes['hasParallax'] ) { |
|
| 165 | - $classes[] = ' has-parallax'; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return sprintf( '<div class="%1$s" style="%2$s" /></div>', implode( ' ', $classes ), $styles ); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Get the styles for the wrapper element (background image, color). |
|
| 173 | - * |
|
| 174 | - * @param array $attributes Block attributes. Default empty array. |
|
| 175 | - * @param string $image_url Item image url. |
|
| 176 | - * |
|
| 177 | - * @return string |
|
| 178 | - */ |
|
| 179 | - public function get_bg_styles( $attributes, $image_url ) { |
|
| 180 | - $style = ''; |
|
| 181 | - |
|
| 182 | - if ( $attributes['isRepeated'] || $attributes['hasParallax'] ) { |
|
| 183 | - $style .= "background-image: url($image_url);"; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - if ( ! $attributes['isRepeated'] ) { |
|
| 187 | - $style .= 'background-repeat: no-repeat;'; |
|
| 188 | - |
|
| 189 | - $bg_size = 'cover' === $attributes['imageFit'] ? $attributes['imageFit'] : 'auto'; |
|
| 190 | - $style .= 'background-size: ' . $bg_size . ';'; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - if ( $this->hasFocalPoint( $attributes ) ) { |
|
| 194 | - $style .= sprintf( |
|
| 195 | - 'background-position: %s%% %s%%;', |
|
| 196 | - $attributes['focalPoint']['x'] * 100, |
|
| 197 | - $attributes['focalPoint']['y'] * 100 |
|
| 198 | - ); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - $global_style_style = StyleAttributesUtils::get_styles_by_attributes( $attributes, $this->global_style_wrapper ); |
|
| 202 | - $style .= $global_style_style; |
|
| 203 | - |
|
| 204 | - return $style; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Renders the featured image |
|
| 209 | - * |
|
| 210 | - * @param array $attributes Block attributes. Default empty array. |
|
| 211 | - * @param \WC_Product|\WP_Term $item Item object. |
|
| 212 | - * @param string $image_url Item image url. |
|
| 213 | - * |
|
| 214 | - * @return string |
|
| 215 | - */ |
|
| 216 | - private function render_image( $attributes, $item, string $image_url ) { |
|
| 217 | - $style = sprintf( 'object-fit: %s;', $attributes['imageFit'] ); |
|
| 218 | - |
|
| 219 | - if ( $this->hasFocalPoint( $attributes ) ) { |
|
| 220 | - $style .= sprintf( |
|
| 221 | - 'object-position: %s%% %s%%;', |
|
| 222 | - $attributes['focalPoint']['x'] * 100, |
|
| 223 | - $attributes['focalPoint']['y'] * 100 |
|
| 224 | - ); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - if ( ! empty( $image_url ) ) { |
|
| 228 | - return sprintf( |
|
| 229 | - '<img alt="%1$s" class="wc-block-%2$s__background-image" src="%3$s" style="%4$s" />', |
|
| 230 | - wp_kses_post( $attributes['alt'] ?: $this->get_item_title( $item ) ), |
|
| 231 | - $this->block_name, |
|
| 232 | - $image_url, |
|
| 233 | - $style |
|
| 234 | - ); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - return ''; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Get the styles for the wrapper element (background image, color). |
|
| 242 | - * |
|
| 243 | - * @param array $attributes Block attributes. Default empty array. |
|
| 244 | - * @return string |
|
| 245 | - */ |
|
| 246 | - public function get_styles( $attributes ) { |
|
| 247 | - $style = ''; |
|
| 248 | - |
|
| 249 | - $min_height = $attributes['minHeight'] ?? wc_get_theme_support( 'featured_block::default_height', 500 ); |
|
| 250 | - |
|
| 251 | - if ( isset( $attributes['minHeight'] ) ) { |
|
| 252 | - $style .= sprintf( 'min-height:%dpx;', intval( $min_height ) ); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $global_style_style = StyleAttributesUtils::get_styles_by_attributes( $attributes, $this->global_style_wrapper ); |
|
| 256 | - $style .= $global_style_style; |
|
| 257 | - |
|
| 258 | - return $style; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Get class names for the block container. |
|
| 264 | - * |
|
| 265 | - * @param array $attributes Block attributes. Default empty array. |
|
| 266 | - * @return string |
|
| 267 | - */ |
|
| 268 | - public function get_classes( $attributes ) { |
|
| 269 | - $classes = array( 'wc-block-' . $this->block_name ); |
|
| 270 | - |
|
| 271 | - if ( isset( $attributes['align'] ) ) { |
|
| 272 | - $classes[] = "align{$attributes['align']}"; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - if ( isset( $attributes['dimRatio'] ) && ( 0 !== $attributes['dimRatio'] ) ) { |
|
| 276 | - $classes[] = 'has-background-dim'; |
|
| 277 | - |
|
| 278 | - if ( 50 !== $attributes['dimRatio'] ) { |
|
| 279 | - $classes[] = 'has-background-dim-' . 10 * round( $attributes['dimRatio'] / 10 ); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - if ( isset( $attributes['contentAlign'] ) && 'center' !== $attributes['contentAlign'] ) { |
|
| 284 | - $classes[] = "has-{$attributes['contentAlign']}-content"; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - if ( isset( $attributes['className'] ) ) { |
|
| 288 | - $classes[] = $attributes['className']; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - $global_style_classes = StyleAttributesUtils::get_classes_by_attributes( $attributes, $this->global_style_wrapper ); |
|
| 292 | - |
|
| 293 | - $classes[] = $global_style_classes; |
|
| 294 | - |
|
| 295 | - return implode( ' ', $classes ); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * Renders the block overlay |
|
| 300 | - * |
|
| 301 | - * @param array $attributes Block attributes. Default empty array. |
|
| 302 | - * |
|
| 303 | - * @return string |
|
| 304 | - */ |
|
| 305 | - private function render_overlay( $attributes ) { |
|
| 306 | - if ( isset( $attributes['overlayGradient'] ) ) { |
|
| 307 | - $overlay_styles = sprintf( 'background-image: %s', $attributes['overlayGradient'] ); |
|
| 308 | - } elseif ( isset( $attributes['overlayColor'] ) ) { |
|
| 309 | - $overlay_styles = sprintf( 'background-color: %s', $attributes['overlayColor'] ); |
|
| 310 | - } else { |
|
| 311 | - $overlay_styles = 'background-color: #000000'; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - return sprintf( '<div class="background-dim__overlay" style="%s"></div>', esc_attr( $overlay_styles ) ); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * Returns whether the focal point is defined for the block. |
|
| 319 | - * |
|
| 320 | - * @param array $attributes Block attributes. Default empty array. |
|
| 321 | - * |
|
| 322 | - * @return bool |
|
| 323 | - */ |
|
| 324 | - private function hasFocalPoint( $attributes ): bool { |
|
| 325 | - return is_array( $attributes['focalPoint'] ) && 2 === count( $attributes['focalPoint'] ); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * Extra data passed through from server to client for block. |
|
| 330 | - * |
|
| 331 | - * @param array $attributes Any attributes that currently are available from the block. |
|
| 332 | - * Note, this will be empty in the editor context when the block is |
|
| 333 | - * not in the post content on editor load. |
|
| 334 | - */ |
|
| 335 | - protected function enqueue_data( array $attributes = [] ) { |
|
| 336 | - parent::enqueue_data( $attributes ); |
|
| 337 | - $this->asset_data_registry->add( 'min_height', wc_get_theme_support( 'featured_block::min_height', 500 ), true ); |
|
| 338 | - $this->asset_data_registry->add( 'default_height', wc_get_theme_support( 'featured_block::default_height', 500 ), true ); |
|
| 339 | - } |
|
| 11 | + /** |
|
| 12 | + * Block name. |
|
| 13 | + * |
|
| 14 | + * @var string |
|
| 15 | + */ |
|
| 16 | + protected $block_name; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * Default attribute values. |
|
| 20 | + * |
|
| 21 | + * @var array |
|
| 22 | + */ |
|
| 23 | + protected $defaults = array( |
|
| 24 | + 'align' => 'none', |
|
| 25 | + ); |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Global style enabled for this block. |
|
| 29 | + * |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $global_style_wrapper = array( |
|
| 33 | + 'background_color', |
|
| 34 | + 'border_color', |
|
| 35 | + 'border_radius', |
|
| 36 | + 'border_width', |
|
| 37 | + 'font_size', |
|
| 38 | + 'padding', |
|
| 39 | + 'text_color', |
|
| 40 | + ); |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Returns the featured item. |
|
| 44 | + * |
|
| 45 | + * @param array $attributes Block attributes. Default empty array. |
|
| 46 | + * @return \WP_Term|\WC_Product|null |
|
| 47 | + */ |
|
| 48 | + abstract protected function get_item( $attributes ); |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Returns the name of the featured item. |
|
| 52 | + * |
|
| 53 | + * @param \WP_Term|\WC_Product $item Item object. |
|
| 54 | + * @return string |
|
| 55 | + */ |
|
| 56 | + abstract protected function get_item_title( $item ); |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Returns the featured item image URL. |
|
| 60 | + * |
|
| 61 | + * @param \WP_Term|\WC_Product $item Item object. |
|
| 62 | + * @param string $size Image size, defaults to 'full'. |
|
| 63 | + * @return string |
|
| 64 | + */ |
|
| 65 | + abstract protected function get_item_image( $item, $size = 'full' ); |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Renders the featured item attributes. |
|
| 69 | + * |
|
| 70 | + * @param \WP_Term|\WC_Product $item Item object. |
|
| 71 | + * @param array $attributes Block attributes. Default empty array. |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + abstract protected function render_attributes( $item, $attributes ); |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Get the supports array for this block type. |
|
| 78 | + * |
|
| 79 | + * @return string[][]; |
|
| 80 | + * @see $this->register_block_type() |
|
| 81 | + */ |
|
| 82 | + protected function get_block_type_supports() { |
|
| 83 | + return array( |
|
| 84 | + 'color' => array( |
|
| 85 | + '__experimentalDuotone' => '.wc-block-' . $this->block_name . '__background-image', |
|
| 86 | + ), |
|
| 87 | + ); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Render the featured item block. |
|
| 92 | + * |
|
| 93 | + * @param array $attributes Block attributes. |
|
| 94 | + * @param string $content Block content. |
|
| 95 | + * @return string Rendered block type output. |
|
| 96 | + */ |
|
| 97 | + protected function render( $attributes, $content ) { |
|
| 98 | + $item = $this->get_item( $attributes ); |
|
| 99 | + if ( ! $item ) { |
|
| 100 | + return ''; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + $attributes = wp_parse_args( $attributes, $this->defaults ); |
|
| 104 | + |
|
| 105 | + $attributes['height'] = $attributes['height'] ?? wc_get_theme_support( 'featured_block::default_height', 500 ); |
|
| 106 | + |
|
| 107 | + $image_url = esc_url( $this->get_image_url( $attributes, $item ) ); |
|
| 108 | + |
|
| 109 | + $styles = $this->get_styles( $attributes ); |
|
| 110 | + $classes = $this->get_classes( $attributes ); |
|
| 111 | + |
|
| 112 | + $output = sprintf( '<div class="%1$s wp-block-woocommerce-%2$s" style="%3$s">', esc_attr( trim( $classes ) ), $this->block_name, esc_attr( $styles ) ); |
|
| 113 | + $output .= sprintf( '<div class="wc-block-%s__wrapper">', $this->block_name ); |
|
| 114 | + $output .= $this->render_overlay( $attributes ); |
|
| 115 | + |
|
| 116 | + if ( ! $attributes['isRepeated'] && ! $attributes['hasParallax'] ) { |
|
| 117 | + $output .= $this->render_image( $attributes, $item, $image_url ); |
|
| 118 | + } else { |
|
| 119 | + $output .= $this->render_bg_image( $attributes, $image_url ); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + $output .= $this->render_attributes( $item, $attributes ); |
|
| 123 | + $output .= sprintf( '<div class="wc-block-%s__link">%s</div>', $this->block_name, $content ); |
|
| 124 | + $output .= '</div>'; |
|
| 125 | + $output .= '</div>'; |
|
| 126 | + |
|
| 127 | + return $output; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Returns the url the item's image |
|
| 132 | + * |
|
| 133 | + * @param array $attributes Block attributes. Default empty array. |
|
| 134 | + * @param \WP_Term|\WC_Product $item Item object. |
|
| 135 | + * |
|
| 136 | + * @return string |
|
| 137 | + */ |
|
| 138 | + private function get_image_url( $attributes, $item ) { |
|
| 139 | + $image_size = 'large'; |
|
| 140 | + if ( 'none' !== $attributes['align'] || $attributes['height'] > 800 ) { |
|
| 141 | + $image_size = 'full'; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + if ( $attributes['mediaId'] ) { |
|
| 145 | + return wp_get_attachment_image_url( $attributes['mediaId'], $image_size ); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + return $this->get_item_image( $item, $image_size ); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Renders the featured image as a div background. |
|
| 153 | + * |
|
| 154 | + * @param array $attributes Block attributes. Default empty array. |
|
| 155 | + * @param string $image_url Item image url. |
|
| 156 | + * |
|
| 157 | + * @return string |
|
| 158 | + */ |
|
| 159 | + private function render_bg_image( $attributes, $image_url ) { |
|
| 160 | + $styles = $this->get_bg_styles( $attributes, $image_url ); |
|
| 161 | + |
|
| 162 | + $classes = [ "wc-block-{$this->block_name}__background-image" ]; |
|
| 163 | + |
|
| 164 | + if ( $attributes['hasParallax'] ) { |
|
| 165 | + $classes[] = ' has-parallax'; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + return sprintf( '<div class="%1$s" style="%2$s" /></div>', implode( ' ', $classes ), $styles ); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Get the styles for the wrapper element (background image, color). |
|
| 173 | + * |
|
| 174 | + * @param array $attributes Block attributes. Default empty array. |
|
| 175 | + * @param string $image_url Item image url. |
|
| 176 | + * |
|
| 177 | + * @return string |
|
| 178 | + */ |
|
| 179 | + public function get_bg_styles( $attributes, $image_url ) { |
|
| 180 | + $style = ''; |
|
| 181 | + |
|
| 182 | + if ( $attributes['isRepeated'] || $attributes['hasParallax'] ) { |
|
| 183 | + $style .= "background-image: url($image_url);"; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + if ( ! $attributes['isRepeated'] ) { |
|
| 187 | + $style .= 'background-repeat: no-repeat;'; |
|
| 188 | + |
|
| 189 | + $bg_size = 'cover' === $attributes['imageFit'] ? $attributes['imageFit'] : 'auto'; |
|
| 190 | + $style .= 'background-size: ' . $bg_size . ';'; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + if ( $this->hasFocalPoint( $attributes ) ) { |
|
| 194 | + $style .= sprintf( |
|
| 195 | + 'background-position: %s%% %s%%;', |
|
| 196 | + $attributes['focalPoint']['x'] * 100, |
|
| 197 | + $attributes['focalPoint']['y'] * 100 |
|
| 198 | + ); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + $global_style_style = StyleAttributesUtils::get_styles_by_attributes( $attributes, $this->global_style_wrapper ); |
|
| 202 | + $style .= $global_style_style; |
|
| 203 | + |
|
| 204 | + return $style; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Renders the featured image |
|
| 209 | + * |
|
| 210 | + * @param array $attributes Block attributes. Default empty array. |
|
| 211 | + * @param \WC_Product|\WP_Term $item Item object. |
|
| 212 | + * @param string $image_url Item image url. |
|
| 213 | + * |
|
| 214 | + * @return string |
|
| 215 | + */ |
|
| 216 | + private function render_image( $attributes, $item, string $image_url ) { |
|
| 217 | + $style = sprintf( 'object-fit: %s;', $attributes['imageFit'] ); |
|
| 218 | + |
|
| 219 | + if ( $this->hasFocalPoint( $attributes ) ) { |
|
| 220 | + $style .= sprintf( |
|
| 221 | + 'object-position: %s%% %s%%;', |
|
| 222 | + $attributes['focalPoint']['x'] * 100, |
|
| 223 | + $attributes['focalPoint']['y'] * 100 |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + if ( ! empty( $image_url ) ) { |
|
| 228 | + return sprintf( |
|
| 229 | + '<img alt="%1$s" class="wc-block-%2$s__background-image" src="%3$s" style="%4$s" />', |
|
| 230 | + wp_kses_post( $attributes['alt'] ?: $this->get_item_title( $item ) ), |
|
| 231 | + $this->block_name, |
|
| 232 | + $image_url, |
|
| 233 | + $style |
|
| 234 | + ); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + return ''; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Get the styles for the wrapper element (background image, color). |
|
| 242 | + * |
|
| 243 | + * @param array $attributes Block attributes. Default empty array. |
|
| 244 | + * @return string |
|
| 245 | + */ |
|
| 246 | + public function get_styles( $attributes ) { |
|
| 247 | + $style = ''; |
|
| 248 | + |
|
| 249 | + $min_height = $attributes['minHeight'] ?? wc_get_theme_support( 'featured_block::default_height', 500 ); |
|
| 250 | + |
|
| 251 | + if ( isset( $attributes['minHeight'] ) ) { |
|
| 252 | + $style .= sprintf( 'min-height:%dpx;', intval( $min_height ) ); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $global_style_style = StyleAttributesUtils::get_styles_by_attributes( $attributes, $this->global_style_wrapper ); |
|
| 256 | + $style .= $global_style_style; |
|
| 257 | + |
|
| 258 | + return $style; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Get class names for the block container. |
|
| 264 | + * |
|
| 265 | + * @param array $attributes Block attributes. Default empty array. |
|
| 266 | + * @return string |
|
| 267 | + */ |
|
| 268 | + public function get_classes( $attributes ) { |
|
| 269 | + $classes = array( 'wc-block-' . $this->block_name ); |
|
| 270 | + |
|
| 271 | + if ( isset( $attributes['align'] ) ) { |
|
| 272 | + $classes[] = "align{$attributes['align']}"; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + if ( isset( $attributes['dimRatio'] ) && ( 0 !== $attributes['dimRatio'] ) ) { |
|
| 276 | + $classes[] = 'has-background-dim'; |
|
| 277 | + |
|
| 278 | + if ( 50 !== $attributes['dimRatio'] ) { |
|
| 279 | + $classes[] = 'has-background-dim-' . 10 * round( $attributes['dimRatio'] / 10 ); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + if ( isset( $attributes['contentAlign'] ) && 'center' !== $attributes['contentAlign'] ) { |
|
| 284 | + $classes[] = "has-{$attributes['contentAlign']}-content"; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + if ( isset( $attributes['className'] ) ) { |
|
| 288 | + $classes[] = $attributes['className']; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + $global_style_classes = StyleAttributesUtils::get_classes_by_attributes( $attributes, $this->global_style_wrapper ); |
|
| 292 | + |
|
| 293 | + $classes[] = $global_style_classes; |
|
| 294 | + |
|
| 295 | + return implode( ' ', $classes ); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * Renders the block overlay |
|
| 300 | + * |
|
| 301 | + * @param array $attributes Block attributes. Default empty array. |
|
| 302 | + * |
|
| 303 | + * @return string |
|
| 304 | + */ |
|
| 305 | + private function render_overlay( $attributes ) { |
|
| 306 | + if ( isset( $attributes['overlayGradient'] ) ) { |
|
| 307 | + $overlay_styles = sprintf( 'background-image: %s', $attributes['overlayGradient'] ); |
|
| 308 | + } elseif ( isset( $attributes['overlayColor'] ) ) { |
|
| 309 | + $overlay_styles = sprintf( 'background-color: %s', $attributes['overlayColor'] ); |
|
| 310 | + } else { |
|
| 311 | + $overlay_styles = 'background-color: #000000'; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + return sprintf( '<div class="background-dim__overlay" style="%s"></div>', esc_attr( $overlay_styles ) ); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * Returns whether the focal point is defined for the block. |
|
| 319 | + * |
|
| 320 | + * @param array $attributes Block attributes. Default empty array. |
|
| 321 | + * |
|
| 322 | + * @return bool |
|
| 323 | + */ |
|
| 324 | + private function hasFocalPoint( $attributes ): bool { |
|
| 325 | + return is_array( $attributes['focalPoint'] ) && 2 === count( $attributes['focalPoint'] ); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * Extra data passed through from server to client for block. |
|
| 330 | + * |
|
| 331 | + * @param array $attributes Any attributes that currently are available from the block. |
|
| 332 | + * Note, this will be empty in the editor context when the block is |
|
| 333 | + * not in the post content on editor load. |
|
| 334 | + */ |
|
| 335 | + protected function enqueue_data( array $attributes = [] ) { |
|
| 336 | + parent::enqueue_data( $attributes ); |
|
| 337 | + $this->asset_data_registry->add( 'min_height', wc_get_theme_support( 'featured_block::min_height', 500 ), true ); |
|
| 338 | + $this->asset_data_registry->add( 'default_height', wc_get_theme_support( 'featured_block::default_height', 500 ), true ); |
|
| 339 | + } |
|
| 340 | 340 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param array $attributes Block attributes. Default empty array. |
| 46 | 46 | * @return \WP_Term|\WC_Product|null |
| 47 | 47 | */ |
| 48 | - abstract protected function get_item( $attributes ); |
|
| 48 | + abstract protected function get_item($attributes); |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * Returns the name of the featured item. |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @param \WP_Term|\WC_Product $item Item object. |
| 54 | 54 | * @return string |
| 55 | 55 | */ |
| 56 | - abstract protected function get_item_title( $item ); |
|
| 56 | + abstract protected function get_item_title($item); |
|
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * Returns the featured item image URL. |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @param string $size Image size, defaults to 'full'. |
| 63 | 63 | * @return string |
| 64 | 64 | */ |
| 65 | - abstract protected function get_item_image( $item, $size = 'full' ); |
|
| 65 | + abstract protected function get_item_image($item, $size = 'full'); |
|
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * Renders the featured item attributes. |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * @param array $attributes Block attributes. Default empty array. |
| 72 | 72 | * @return string |
| 73 | 73 | */ |
| 74 | - abstract protected function render_attributes( $item, $attributes ); |
|
| 74 | + abstract protected function render_attributes($item, $attributes); |
|
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | 77 | * Get the supports array for this block type. |
@@ -94,33 +94,33 @@ discard block |
||
| 94 | 94 | * @param string $content Block content. |
| 95 | 95 | * @return string Rendered block type output. |
| 96 | 96 | */ |
| 97 | - protected function render( $attributes, $content ) { |
|
| 98 | - $item = $this->get_item( $attributes ); |
|
| 99 | - if ( ! $item ) { |
|
| 97 | + protected function render($attributes, $content) { |
|
| 98 | + $item = $this->get_item($attributes); |
|
| 99 | + if (!$item) { |
|
| 100 | 100 | return ''; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - $attributes = wp_parse_args( $attributes, $this->defaults ); |
|
| 103 | + $attributes = wp_parse_args($attributes, $this->defaults); |
|
| 104 | 104 | |
| 105 | - $attributes['height'] = $attributes['height'] ?? wc_get_theme_support( 'featured_block::default_height', 500 ); |
|
| 105 | + $attributes['height'] = $attributes['height'] ?? wc_get_theme_support('featured_block::default_height', 500); |
|
| 106 | 106 | |
| 107 | - $image_url = esc_url( $this->get_image_url( $attributes, $item ) ); |
|
| 107 | + $image_url = esc_url($this->get_image_url($attributes, $item)); |
|
| 108 | 108 | |
| 109 | - $styles = $this->get_styles( $attributes ); |
|
| 110 | - $classes = $this->get_classes( $attributes ); |
|
| 109 | + $styles = $this->get_styles($attributes); |
|
| 110 | + $classes = $this->get_classes($attributes); |
|
| 111 | 111 | |
| 112 | - $output = sprintf( '<div class="%1$s wp-block-woocommerce-%2$s" style="%3$s">', esc_attr( trim( $classes ) ), $this->block_name, esc_attr( $styles ) ); |
|
| 113 | - $output .= sprintf( '<div class="wc-block-%s__wrapper">', $this->block_name ); |
|
| 114 | - $output .= $this->render_overlay( $attributes ); |
|
| 112 | + $output = sprintf('<div class="%1$s wp-block-woocommerce-%2$s" style="%3$s">', esc_attr(trim($classes)), $this->block_name, esc_attr($styles)); |
|
| 113 | + $output .= sprintf('<div class="wc-block-%s__wrapper">', $this->block_name); |
|
| 114 | + $output .= $this->render_overlay($attributes); |
|
| 115 | 115 | |
| 116 | - if ( ! $attributes['isRepeated'] && ! $attributes['hasParallax'] ) { |
|
| 117 | - $output .= $this->render_image( $attributes, $item, $image_url ); |
|
| 116 | + if (!$attributes['isRepeated'] && !$attributes['hasParallax']) { |
|
| 117 | + $output .= $this->render_image($attributes, $item, $image_url); |
|
| 118 | 118 | } else { |
| 119 | - $output .= $this->render_bg_image( $attributes, $image_url ); |
|
| 119 | + $output .= $this->render_bg_image($attributes, $image_url); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - $output .= $this->render_attributes( $item, $attributes ); |
|
| 123 | - $output .= sprintf( '<div class="wc-block-%s__link">%s</div>', $this->block_name, $content ); |
|
| 122 | + $output .= $this->render_attributes($item, $attributes); |
|
| 123 | + $output .= sprintf('<div class="wc-block-%s__link">%s</div>', $this->block_name, $content); |
|
| 124 | 124 | $output .= '</div>'; |
| 125 | 125 | $output .= '</div>'; |
| 126 | 126 | |
@@ -135,17 +135,17 @@ discard block |
||
| 135 | 135 | * |
| 136 | 136 | * @return string |
| 137 | 137 | */ |
| 138 | - private function get_image_url( $attributes, $item ) { |
|
| 138 | + private function get_image_url($attributes, $item) { |
|
| 139 | 139 | $image_size = 'large'; |
| 140 | - if ( 'none' !== $attributes['align'] || $attributes['height'] > 800 ) { |
|
| 140 | + if ('none' !== $attributes['align'] || $attributes['height'] > 800) { |
|
| 141 | 141 | $image_size = 'full'; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if ( $attributes['mediaId'] ) { |
|
| 145 | - return wp_get_attachment_image_url( $attributes['mediaId'], $image_size ); |
|
| 144 | + if ($attributes['mediaId']) { |
|
| 145 | + return wp_get_attachment_image_url($attributes['mediaId'], $image_size); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - return $this->get_item_image( $item, $image_size ); |
|
| 148 | + return $this->get_item_image($item, $image_size); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -156,16 +156,16 @@ discard block |
||
| 156 | 156 | * |
| 157 | 157 | * @return string |
| 158 | 158 | */ |
| 159 | - private function render_bg_image( $attributes, $image_url ) { |
|
| 160 | - $styles = $this->get_bg_styles( $attributes, $image_url ); |
|
| 159 | + private function render_bg_image($attributes, $image_url) { |
|
| 160 | + $styles = $this->get_bg_styles($attributes, $image_url); |
|
| 161 | 161 | |
| 162 | - $classes = [ "wc-block-{$this->block_name}__background-image" ]; |
|
| 162 | + $classes = ["wc-block-{$this->block_name}__background-image"]; |
|
| 163 | 163 | |
| 164 | - if ( $attributes['hasParallax'] ) { |
|
| 164 | + if ($attributes['hasParallax']) { |
|
| 165 | 165 | $classes[] = ' has-parallax'; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - return sprintf( '<div class="%1$s" style="%2$s" /></div>', implode( ' ', $classes ), $styles ); |
|
| 168 | + return sprintf('<div class="%1$s" style="%2$s" /></div>', implode(' ', $classes), $styles); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -176,21 +176,21 @@ discard block |
||
| 176 | 176 | * |
| 177 | 177 | * @return string |
| 178 | 178 | */ |
| 179 | - public function get_bg_styles( $attributes, $image_url ) { |
|
| 179 | + public function get_bg_styles($attributes, $image_url) { |
|
| 180 | 180 | $style = ''; |
| 181 | 181 | |
| 182 | - if ( $attributes['isRepeated'] || $attributes['hasParallax'] ) { |
|
| 182 | + if ($attributes['isRepeated'] || $attributes['hasParallax']) { |
|
| 183 | 183 | $style .= "background-image: url($image_url);"; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - if ( ! $attributes['isRepeated'] ) { |
|
| 186 | + if (!$attributes['isRepeated']) { |
|
| 187 | 187 | $style .= 'background-repeat: no-repeat;'; |
| 188 | 188 | |
| 189 | 189 | $bg_size = 'cover' === $attributes['imageFit'] ? $attributes['imageFit'] : 'auto'; |
| 190 | 190 | $style .= 'background-size: ' . $bg_size . ';'; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - if ( $this->hasFocalPoint( $attributes ) ) { |
|
| 193 | + if ($this->hasFocalPoint($attributes)) { |
|
| 194 | 194 | $style .= sprintf( |
| 195 | 195 | 'background-position: %s%% %s%%;', |
| 196 | 196 | $attributes['focalPoint']['x'] * 100, |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | ); |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - $global_style_style = StyleAttributesUtils::get_styles_by_attributes( $attributes, $this->global_style_wrapper ); |
|
| 201 | + $global_style_style = StyleAttributesUtils::get_styles_by_attributes($attributes, $this->global_style_wrapper); |
|
| 202 | 202 | $style .= $global_style_style; |
| 203 | 203 | |
| 204 | 204 | return $style; |
@@ -213,10 +213,10 @@ discard block |
||
| 213 | 213 | * |
| 214 | 214 | * @return string |
| 215 | 215 | */ |
| 216 | - private function render_image( $attributes, $item, string $image_url ) { |
|
| 217 | - $style = sprintf( 'object-fit: %s;', $attributes['imageFit'] ); |
|
| 216 | + private function render_image($attributes, $item, string $image_url) { |
|
| 217 | + $style = sprintf('object-fit: %s;', $attributes['imageFit']); |
|
| 218 | 218 | |
| 219 | - if ( $this->hasFocalPoint( $attributes ) ) { |
|
| 219 | + if ($this->hasFocalPoint($attributes)) { |
|
| 220 | 220 | $style .= sprintf( |
| 221 | 221 | 'object-position: %s%% %s%%;', |
| 222 | 222 | $attributes['focalPoint']['x'] * 100, |
@@ -224,10 +224,10 @@ discard block |
||
| 224 | 224 | ); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - if ( ! empty( $image_url ) ) { |
|
| 227 | + if (!empty($image_url)) { |
|
| 228 | 228 | return sprintf( |
| 229 | 229 | '<img alt="%1$s" class="wc-block-%2$s__background-image" src="%3$s" style="%4$s" />', |
| 230 | - wp_kses_post( $attributes['alt'] ?: $this->get_item_title( $item ) ), |
|
| 230 | + wp_kses_post($attributes['alt'] ?: $this->get_item_title($item)), |
|
| 231 | 231 | $this->block_name, |
| 232 | 232 | $image_url, |
| 233 | 233 | $style |
@@ -243,16 +243,16 @@ discard block |
||
| 243 | 243 | * @param array $attributes Block attributes. Default empty array. |
| 244 | 244 | * @return string |
| 245 | 245 | */ |
| 246 | - public function get_styles( $attributes ) { |
|
| 246 | + public function get_styles($attributes) { |
|
| 247 | 247 | $style = ''; |
| 248 | 248 | |
| 249 | - $min_height = $attributes['minHeight'] ?? wc_get_theme_support( 'featured_block::default_height', 500 ); |
|
| 249 | + $min_height = $attributes['minHeight'] ?? wc_get_theme_support('featured_block::default_height', 500); |
|
| 250 | 250 | |
| 251 | - if ( isset( $attributes['minHeight'] ) ) { |
|
| 252 | - $style .= sprintf( 'min-height:%dpx;', intval( $min_height ) ); |
|
| 251 | + if (isset($attributes['minHeight'])) { |
|
| 252 | + $style .= sprintf('min-height:%dpx;', intval($min_height)); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - $global_style_style = StyleAttributesUtils::get_styles_by_attributes( $attributes, $this->global_style_wrapper ); |
|
| 255 | + $global_style_style = StyleAttributesUtils::get_styles_by_attributes($attributes, $this->global_style_wrapper); |
|
| 256 | 256 | $style .= $global_style_style; |
| 257 | 257 | |
| 258 | 258 | return $style; |
@@ -265,34 +265,34 @@ discard block |
||
| 265 | 265 | * @param array $attributes Block attributes. Default empty array. |
| 266 | 266 | * @return string |
| 267 | 267 | */ |
| 268 | - public function get_classes( $attributes ) { |
|
| 269 | - $classes = array( 'wc-block-' . $this->block_name ); |
|
| 268 | + public function get_classes($attributes) { |
|
| 269 | + $classes = array('wc-block-' . $this->block_name); |
|
| 270 | 270 | |
| 271 | - if ( isset( $attributes['align'] ) ) { |
|
| 271 | + if (isset($attributes['align'])) { |
|
| 272 | 272 | $classes[] = "align{$attributes['align']}"; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - if ( isset( $attributes['dimRatio'] ) && ( 0 !== $attributes['dimRatio'] ) ) { |
|
| 275 | + if (isset($attributes['dimRatio']) && (0 !== $attributes['dimRatio'])) { |
|
| 276 | 276 | $classes[] = 'has-background-dim'; |
| 277 | 277 | |
| 278 | - if ( 50 !== $attributes['dimRatio'] ) { |
|
| 279 | - $classes[] = 'has-background-dim-' . 10 * round( $attributes['dimRatio'] / 10 ); |
|
| 278 | + if (50 !== $attributes['dimRatio']) { |
|
| 279 | + $classes[] = 'has-background-dim-' . 10 * round($attributes['dimRatio'] / 10); |
|
| 280 | 280 | } |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - if ( isset( $attributes['contentAlign'] ) && 'center' !== $attributes['contentAlign'] ) { |
|
| 283 | + if (isset($attributes['contentAlign']) && 'center' !== $attributes['contentAlign']) { |
|
| 284 | 284 | $classes[] = "has-{$attributes['contentAlign']}-content"; |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - if ( isset( $attributes['className'] ) ) { |
|
| 287 | + if (isset($attributes['className'])) { |
|
| 288 | 288 | $classes[] = $attributes['className']; |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - $global_style_classes = StyleAttributesUtils::get_classes_by_attributes( $attributes, $this->global_style_wrapper ); |
|
| 291 | + $global_style_classes = StyleAttributesUtils::get_classes_by_attributes($attributes, $this->global_style_wrapper); |
|
| 292 | 292 | |
| 293 | 293 | $classes[] = $global_style_classes; |
| 294 | 294 | |
| 295 | - return implode( ' ', $classes ); |
|
| 295 | + return implode(' ', $classes); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | /** |
@@ -302,16 +302,16 @@ discard block |
||
| 302 | 302 | * |
| 303 | 303 | * @return string |
| 304 | 304 | */ |
| 305 | - private function render_overlay( $attributes ) { |
|
| 306 | - if ( isset( $attributes['overlayGradient'] ) ) { |
|
| 307 | - $overlay_styles = sprintf( 'background-image: %s', $attributes['overlayGradient'] ); |
|
| 308 | - } elseif ( isset( $attributes['overlayColor'] ) ) { |
|
| 309 | - $overlay_styles = sprintf( 'background-color: %s', $attributes['overlayColor'] ); |
|
| 305 | + private function render_overlay($attributes) { |
|
| 306 | + if (isset($attributes['overlayGradient'])) { |
|
| 307 | + $overlay_styles = sprintf('background-image: %s', $attributes['overlayGradient']); |
|
| 308 | + } elseif (isset($attributes['overlayColor'])) { |
|
| 309 | + $overlay_styles = sprintf('background-color: %s', $attributes['overlayColor']); |
|
| 310 | 310 | } else { |
| 311 | 311 | $overlay_styles = 'background-color: #000000'; |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - return sprintf( '<div class="background-dim__overlay" style="%s"></div>', esc_attr( $overlay_styles ) ); |
|
| 314 | + return sprintf('<div class="background-dim__overlay" style="%s"></div>', esc_attr($overlay_styles)); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
@@ -321,8 +321,8 @@ discard block |
||
| 321 | 321 | * |
| 322 | 322 | * @return bool |
| 323 | 323 | */ |
| 324 | - private function hasFocalPoint( $attributes ): bool { |
|
| 325 | - return is_array( $attributes['focalPoint'] ) && 2 === count( $attributes['focalPoint'] ); |
|
| 324 | + private function hasFocalPoint($attributes): bool { |
|
| 325 | + return is_array($attributes['focalPoint']) && 2 === count($attributes['focalPoint']); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -332,9 +332,9 @@ discard block |
||
| 332 | 332 | * Note, this will be empty in the editor context when the block is |
| 333 | 333 | * not in the post content on editor load. |
| 334 | 334 | */ |
| 335 | - protected function enqueue_data( array $attributes = [] ) { |
|
| 336 | - parent::enqueue_data( $attributes ); |
|
| 337 | - $this->asset_data_registry->add( 'min_height', wc_get_theme_support( 'featured_block::min_height', 500 ), true ); |
|
| 338 | - $this->asset_data_registry->add( 'default_height', wc_get_theme_support( 'featured_block::default_height', 500 ), true ); |
|
| 335 | + protected function enqueue_data(array $attributes = []) { |
|
| 336 | + parent::enqueue_data($attributes); |
|
| 337 | + $this->asset_data_registry->add('min_height', wc_get_theme_support('featured_block::min_height', 500), true); |
|
| 338 | + $this->asset_data_registry->add('default_height', wc_get_theme_support('featured_block::default_height', 500), true); |
|
| 339 | 339 | } |
| 340 | 340 | } |