Fix Product Categories List align attribute (https://github.com/woocommerce/woocommerce-blocks/pull/2700)
* Fix Product Categories List with align attribute * Add support to align attribute to the Product Categories List block
This commit is contained in:
parent
582ba8797f
commit
b0ef232271
|
@ -35,6 +35,13 @@ registerBlockType( 'woocommerce/product-categories', {
|
|||
},
|
||||
},
|
||||
attributes: {
|
||||
/**
|
||||
* Alignment of the block.
|
||||
*/
|
||||
align: {
|
||||
type: 'string',
|
||||
},
|
||||
|
||||
/**
|
||||
* Whether to show the product count in each category.
|
||||
*/
|
||||
|
|
|
@ -43,6 +43,7 @@ class ProductCategories extends AbstractDynamicBlock {
|
|||
return array_merge(
|
||||
parent::get_attributes(),
|
||||
array(
|
||||
'align' => $this->get_schema_align(),
|
||||
'className' => $this->get_schema_string(),
|
||||
'hasCount' => $this->get_schema_boolean( true ),
|
||||
'hasImage' => $this->get_schema_boolean( false ),
|
||||
|
@ -84,13 +85,41 @@ class ProductCategories extends AbstractDynamicBlock {
|
|||
}
|
||||
}
|
||||
|
||||
$output = '<div class="wc-block-product-categories ' . esc_attr( $attributes['className'] ) . ' ' . ( $attributes['isDropdown'] ? 'is-dropdown' : 'is-list' ) . '">';
|
||||
$classes = $this->get_container_classes( $attributes );
|
||||
|
||||
$output = '<div class="' . esc_attr( $classes ) . '">';
|
||||
$output .= ! empty( $attributes['isDropdown'] ) ? $this->renderDropdown( $categories, $attributes, $uid ) : $this->renderList( $categories, $attributes, $uid );
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of classes to apply to this block.
|
||||
*
|
||||
* @param array $attributes Block attributes. Default empty array.
|
||||
* @return string space-separated list of classes.
|
||||
*/
|
||||
protected function get_container_classes( $attributes = array() ) {
|
||||
$classes = array( 'wc-block-product-categories' );
|
||||
|
||||
if ( isset( $attributes['align'] ) ) {
|
||||
$classes[] = "align{$attributes['align']}";
|
||||
}
|
||||
|
||||
if ( ! empty( $attributes['className'] ) ) {
|
||||
$classes[] = $attributes['className'];
|
||||
}
|
||||
|
||||
if ( $attributes['isDropdown'] ) {
|
||||
$classes[] = 'is-dropdown';
|
||||
} else {
|
||||
$classes[] = 'is-list';
|
||||
}
|
||||
|
||||
return implode( ' ', $classes );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get categories (terms) from the db.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue