Automattic\WooCommerce\Blocks\BlockTypes

ProductFilterActive::render()protectedWC 1.0

Render the block.

Method of the class: ProductFilterActive{}

No Hooks.

Return

String. Rendered block type output.

Usage

// protected - for code of main (parent) or child class
$result = $this->render( $attributes, $content, $block );
$attributes(array) (required)
Block attributes.
$content(string) (required)
Block content.
$block(WP_Block) (required)
Block instance.

ProductFilterActive::render() code WC 9.7.1

protected function render( $attributes, $content, $block ) {
	if ( ! isset( $block->context['activeFilters'] ) ) {
		return $content;
	}

	$active_filters = $block->context['activeFilters'];

	$filter_context = array(
		'items'  => $active_filters,
		'parent' => $this->get_full_block_name(),
	);

	$wrapper_attributes = array(
		'data-wc-interactive'  => wp_json_encode( array( 'namespace' => $this->get_full_block_name() ), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP ),
		'data-wc-key'          => wp_unique_prefixed_id( $this->get_full_block_name() ),
		'data-wc-bind--hidden' => '!state.hasSelectedFilters',
		/* translators:  {{label}} is the label of the active filter item. */
		'data-wc-context'      => wp_json_encode( array( 'removeLabelTemplate' => __( 'Remove filter: {{label}}', 'woocommerce' ) ), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP ),
	);

	if ( empty( $active_filters ) ) {
		$wrapper_attributes['hidden'] = true;
	}

	return sprintf(
		'<div %1$s>%2$s</div>',
		get_block_wrapper_attributes( $wrapper_attributes ),
		array_reduce(
			$block->parsed_block['innerBlocks'],
			function ( $carry, $parsed_block ) use ( $filter_context ) {
				$carry .= ( new \WP_Block( $parsed_block, array( 'filterData' => $filter_context ) ) )->render();
				return $carry;
			},
			''
		)
	);
}