From 61663068e82e8ae0ab80d1c789fa436d1b875a10 Mon Sep 17 00:00:00 2001 From: Luigi Date: Mon, 27 Dec 2021 11:30:12 +0100 Subject: [PATCH] rename function --- src/BlockTypes/LegacyTemplate.php | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/BlockTypes/LegacyTemplate.php b/src/BlockTypes/LegacyTemplate.php index 2b24438a018..969d668450c 100644 --- a/src/BlockTypes/LegacyTemplate.php +++ b/src/BlockTypes/LegacyTemplate.php @@ -23,19 +23,12 @@ class LegacyTemplate extends AbstractDynamicBlock { */ protected $api_version = '2'; - /** - * List of archive legacy template. - * - * @var array - */ - protected $archive_templates = array( 'archive-product', 'taxonomy-product_cat', 'taxonomy-product_tag' ); - /** * Initialize this block. */ protected function initialize() { parent::initialize(); - add_filter( 'render_block', array( $this, 'get_markup_with_classes_by_attributes' ), 10, 2 ); + add_filter( 'render_block', array( $this, 'add_alignment_class_to_wrapper' ), 10, 2 ); } /** @@ -59,9 +52,11 @@ protected function render( $attributes, $content ) { $frontend_scripts::load_scripts(); } + $archive_templates = array( 'archive-product', 'taxonomy-product_cat', 'taxonomy-product_tag' ); + if ( 'single-product' === $attributes['template'] ) { return $this->render_single_product(); - } elseif ( in_array( $attributes['template'], $this->archive_templates, true ) ) { + } elseif ( in_array( $attributes['template'], $archive_templates, true ) ) { return $this->render_archive_product(); } else { ob_start(); @@ -205,8 +200,8 @@ protected function render_archive_product() { * @param array $block Parsed block data. * @return string Rendered block type output. */ - public function get_markup_with_classes_by_attributes( string $content, array $block ) { - if ( ! $this->is_legacy_template( $block ) ) { + public function add_alignment_class_to_wrapper( string $content, array $block ) { + if ( ( 'woocommerce/' . $this->block_name ) !== $block['blockName'] ) { return $content; } @@ -223,15 +218,5 @@ public function get_markup_with_classes_by_attributes( string $content, array $b return preg_replace( $pattern, $matches[0] . ' ' . $align_class_and_style['class'], $content, 1 ); } - /** - * Check if the block is a legacy template. - * - * @param array $block Parsed block data. - * @return boolean - */ - protected function is_legacy_template( $block ) { - $attributes = (array) $block['attrs']; - return isset( $attributes['template'] ) && ( in_array( $attributes['template'], $this->archive_templates, true ) || 'single-product' === $attributes['template'] ); - } }