Automattic\WooCommerce\Blocks\BlockTypes

FeaturedItem::render_image()privateWC 1.0

Renders the featured image

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

Хуков нет.

Возвращает

Строку.

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

// private - только в коде основоного (родительского) класса
$result = $this->render_image( $attributes, $item, $image_url );
$attributes(массив) (обязательный)
Block attributes.
По умолчанию: empty array
$item(\WC_Product|\WP_Term) (обязательный)
Item object.
$image_url(строка) (обязательный)
Item image url.

Код FeaturedItem::render_image() WC 8.7.0

private function render_image( $attributes, $item, string $image_url ) {
	$style   = sprintf( 'object-fit: %s;', esc_attr( $attributes['imageFit'] ) );
	$img_alt = $attributes['alt'] ?: $this->get_item_title( $item );

	if ( $this->hasFocalPoint( $attributes ) ) {
		$style .= sprintf(
			'object-position: %s%% %s%%;',
			$attributes['focalPoint']['x'] * 100,
			$attributes['focalPoint']['y'] * 100
		);
	}

	if ( ! empty( $image_url ) ) {
		return sprintf(
			'<img alt="%1$s" class="wc-block-%2$s__background-image" src="%3$s" style="%4$s" />',
			esc_attr( $img_alt ),
			$this->block_name,
			esc_url( $image_url ),
			esc_attr( $style )
		);
	}

	return '';
}