From bf53dd3d98c9d71aff17653cd792a2dec3e1dcb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Tue, 24 May 2022 16:10:16 +0200 Subject: [PATCH] Add `Fixed/Repeated background` to the `Featured Category` block (#6440) * Add `Fixed/Repeated background` to the `Featured Category` block * Reorganize `Featured Product` and `Feature Category` before unification * Fix gradient overlay --- assets/css/abstracts/_mixins.scss | 2 +- .../featured-category/block.json | 8 + src/BlockTypes/FeaturedCategory.php | 155 +++++++++++++----- src/BlockTypes/FeaturedProduct.php | 95 ++++++----- 4 files changed, 173 insertions(+), 87 deletions(-) diff --git a/assets/css/abstracts/_mixins.scss b/assets/css/abstracts/_mixins.scss index 96e1735c2f8..906e72a2bce 100644 --- a/assets/css/abstracts/_mixins.scss +++ b/assets/css/abstracts/_mixins.scss @@ -217,7 +217,7 @@ $fontSizes: ( left: 0; bottom: 0; right: 0; - background-color: inherit; + background: inherit; border-radius: inherit; opacity: $opacity; z-index: 1; diff --git a/assets/js/blocks/featured-items/featured-category/block.json b/assets/js/blocks/featured-items/featured-category/block.json index 5cca01685d9..da1da21ae70 100644 --- a/assets/js/blocks/featured-items/featured-category/block.json +++ b/assets/js/blocks/featured-items/featured-category/block.json @@ -57,6 +57,14 @@ "type": "string", "default": "none" }, + "hasParallax": { + "type": "boolean", + "default": false + }, + "isRepeated": { + "type": "boolean", + "default": false + }, "mediaId": { "type": "number", "default": 0 diff --git a/src/BlockTypes/FeaturedCategory.php b/src/BlockTypes/FeaturedCategory.php index 00e7d7b0393..52d2bcbd04f 100644 --- a/src/BlockTypes/FeaturedCategory.php +++ b/src/BlockTypes/FeaturedCategory.php @@ -14,6 +14,14 @@ class FeaturedCategory extends AbstractDynamicBlock { */ protected $block_name = 'featured-category'; + /** + * Default attribute values, should match what's set in JS `registerBlockType`. + * + * @var array + */ + protected $defaults = array( + 'align' => 'none', + ); /** * Global style enabled for this block. @@ -45,15 +53,6 @@ protected function get_block_type_supports() { ); } - /** - * Default attribute values, should match what's set in JS `registerBlockType`. - * - * @var array - */ - protected $defaults = array( - 'align' => 'none', - ); - /** * Get block attributes. * @@ -79,17 +78,16 @@ protected function get_block_type_attributes() { * @return string Rendered block type output. */ protected function render( $attributes, $content ) { + $id = absint( $attributes['categoryId'] ?? 0 ); - $id = absint( isset( $attributes['categoryId'] ) ? $attributes['categoryId'] : 0 ); $category = get_term( $id, 'product_cat' ); - if ( ! $category || is_wp_error( $category ) ) { return ''; } $attributes = wp_parse_args( $attributes, $this->defaults ); - $attributes['height'] = isset( $attributes['height'] ) ? $attributes['height'] : wc_get_theme_support( 'featured_block::default_height', 500 ); + $attributes['height'] = $attributes['height'] ?? wc_get_theme_support( 'featured_block::default_height', 500 ); $title = sprintf( '', @@ -101,13 +99,21 @@ protected function render( $attributes, $content ) { wc_format_content( wp_kses_post( $category->description ) ) ); + $image_url = esc_url( $this->get_image_url( $attributes, $category ) ); + $styles = $this->get_styles( $attributes ); $classes = $this->get_classes( $attributes ); $output = sprintf( '