Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed Dec 27, 2021
1 parent bb19d24 commit 6166306
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions src/BlockTypes/LegacyTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}

Expand All @@ -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'] );
}

}

0 comments on commit 6166306

Please sign in to comment.