Automattic\WooCommerce\Blocks\BlockTypes

ProductImage::renderprotectedWC 1.0

Include and render the block

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

Хуков нет.

Возвращает

Строку. Rendered block type output.

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

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

Код ProductImage::render() WC 11.0.0

protected function render( $attributes, $content, $block ) {
	$parsed_attributes     = $this->parse_attributes( $attributes );
	$classes_and_styles    = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, array(), array( 'extra_classes' ) );
	$post_id               = isset( $block->context['postId'] ) ? $block->context['postId'] : '';
	$image_id              = isset( $block->context['imageId'] ) ? (int) $block->context['imageId'] : null;
	$product               = wc_get_product( $post_id );
	$resolved_aspect_ratio = $this->resolve_aspect_ratio( $parsed_attributes );
	$aspect_ratio_class    = 'wc-block-components-product-image--aspect-ratio-' . ( $resolved_aspect_ratio ? str_replace( '/', '-', $resolved_aspect_ratio ) : 'auto' );

	$classes = implode(
		' ',
		array_filter(
			array(
				'wc-block-components-product-image wc-block-grid__product-image',
				$aspect_ratio_class,
				esc_attr( $classes_and_styles['classes'] ),
			)
		)
	);

	$wrapper_attributes = get_block_wrapper_attributes(
		array(
			'class' => esc_attr( $classes ),
			'style' => esc_attr( $classes_and_styles['styles'] ),
		)
	);

	if ( $product ) {
		$inner_content = $this->render_anchor(
			$product,
			$this->render_on_sale_badge( $product, $parsed_attributes ),
			$this->render_image( $product, $parsed_attributes, $image_id ),
			$attributes,
			$content
		);

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

	return '';
}