Automattic\WooCommerce\Blocks\BlockTypes

Breadcrumbs::renderprotectedWC 1.0

Render the block.

Метод класса: Breadcrumbs{}

Хуков нет.

Возвращает

Строку. | void Rendered block output.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->render( $attributes, $content, $block );
$attributes(массив) (обязательный)
Block attributes.
$content(строка) (обязательный)
Block content.
$block(WP_Block) (обязательный)
Block instance.

Код Breadcrumbs::render() WC 11.0.1

protected function render( $attributes, $content, $block ) {
	ob_start();
	woocommerce_breadcrumb();
	$breadcrumb = ob_get_clean();

	if ( ! $breadcrumb ) {
		return;
	}

	$classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, array(), array( 'font_size' ) );

	$font_size_classes_and_styles  = $this->get_font_size_classes_and_styles( $attributes, $block );
	$classes_and_styles['classes'] = $classes_and_styles['classes'] . ' ' . ( $font_size_classes_and_styles['class'] ?? '' ) . ' ';
	$classes_and_styles['styles']  = $classes_and_styles['styles'] . ' ' . ( $font_size_classes_and_styles['style'] ?? '' ) . ' ';

	$wrapper_attributes = get_block_wrapper_attributes(
		array(
			'class' => 'woocommerce wc-block-breadcrumbs ' . trim( $classes_and_styles['classes'] ),
			'style' => trim( $classes_and_styles['styles'] ),
		)
	);

	$has_non_small_custom_font_size = strpos( $font_size_classes_and_styles['class'] ?? '', 'has-small-font-size' ) === false;

	// Remove the default 'has-small-font-size' class when the block has a custom font size different from small.
	// This is needed because the block.json defines a default font size, which is considered an anti-pattern
	// since styles should be defined by themes and plugins instead.
	if ( $has_non_small_custom_font_size ) {
		$wrapper_attributes = str_replace( 'has-small-font-size', '', $wrapper_attributes );
	}

	return sprintf(
		'<div %1$s>%2$s</div>',
		$wrapper_attributes,
		$breadcrumb
	);
}