Automattic\WooCommerce\Blocks\Templates

ProductFiltersTemplate::register_block_type_variation()publicWC 1.0

Add variation for this template part to make it available in the block inserter.

Method of the class: ProductFiltersTemplate{}

No Hooks.

Return

null. Nothing (null).

Usage

$ProductFiltersTemplate = new ProductFiltersTemplate();
$ProductFiltersTemplate->register_block_type_variation( $variations, $block_type );
$variations(array) (required)
Array of registered variations for a block type.
$block_type(WP_Block_Type) (required)
The full block type object.

ProductFiltersTemplate::register_block_type_variation() code WC 9.4.2

public function register_block_type_variation( $variations, $block_type ) {
	if ( 'core/template-part' !== $block_type->name ) {
		return $variations;
	}

	// If template part is modified, Core will pick it up and register a variation
	// for it. Check if the variation already exists before adding it.
	foreach ( $variations as $variation ) {
		if ( ! empty( $variation['attributes']['slug'] ) && 'product-filters' === $variation['attributes']['slug'] ) {
				return $variations;
		}
	}

	$theme = 'woocommerce/woocommerce';
	// Check if current theme overrides this template part.
	if ( BlockTemplateUtils::theme_has_template_part( 'product-filters' ) ) {
		$theme = wp_get_theme()->get( 'TextDomain' );
	}

	$variations[] = array(
		'name'        => 'file_' . self::SLUG,
		'title'       => $this->get_template_title(),
		'description' => true,
		'attributes'  => array(
			'slug'  => self::SLUG,
			'theme' => $theme,
			'area'  => $this->template_area,
		),
		'scope'       => array( 'inserter' ),
		'icon'        => 'layout',
	);
	return $variations;
}