Automattic\WooCommerce\Blocks\BlockTypes

ProductFiltersOverlayNavigation::render()protectedWC 1.0

Include and render the block.

Method of the class: ProductFiltersOverlayNavigation{}

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.
Default: empty array
$content(string) (required)
Block content.
Default: empty string
$block(WP_Block) (required)
Block instance.

ProductFiltersOverlayNavigation::render() code WC 9.4.2

protected function render( $attributes, $content, $block ) {
	$wrapper_attributes = get_block_wrapper_attributes(
		array(
			'class' => 'wc-block-product-filters-overlay-navigation',
		)
	);
	$overlay_mode       = isset( $block->context['woocommerce/product-filters/overlay'] ) ? $block->context['woocommerce/product-filters/overlay'] : 'never';

	if ( 'open-overlay' === $attributes['triggerType'] && ( 'never' === $overlay_mode || ( ! wp_is_mobile() && 'mobile' === $overlay_mode ) ) ) {
		return null;
	}

	$html = strtr(
		'<div {{wrapper_attributes}}>
			{{primary_content}}
			{{secondary_content}}
		</div>',
		array(
			'{{wrapper_attributes}}' => $wrapper_attributes,
			'{{primary_content}}'    => 'open-overlay' === $attributes['triggerType'] ? $this->render_icon( $attributes ) : $this->render_label( $attributes ),
			'{{secondary_content}}'  => 'open-overlay' === $attributes['triggerType'] ? $this->render_label( $attributes ) : $this->render_icon( $attributes ),
		)
	);

	$p = new \WP_HTML_Tag_Processor( $html );

	if ( $p->next_tag() ) {
		$p->set_attribute( 'data-wc-interactive', wp_json_encode( array( 'namespace' => 'woocommerce/product-filters' ), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP ) );
		$p->set_attribute(
			'data-wc-on--click',
			'open-overlay' === $attributes['triggerType'] ? 'actions.openDialog' : 'actions.closeDialog'
		);
		$p->set_attribute( 'data-wc-class--hidden', 'open-overlay' === $attributes['triggerType'] ? 'state.isDialogOpen' : '!state.isDialogOpen' );
		$html = $p->get_updated_html();
	}

	return $html;
}