Automattic\WooCommerce\Blocks\BlockTypes

ProductGallery::resolve_product_image_aspect_ratioprivateWC 1.0

Resolve the gallery aspect ratio from the nested Product Image block.

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

Хуков нет.

Возвращает

string|null. CSS aspect ratio value, or null when no ratio should be applied.

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

// private - только в коде основоного (родительского) класса
$result = $this->resolve_product_image_aspect_ratio( $block );
$block(WP_Block) (обязательный)
The Product Gallery block.

Код ProductGallery::resolve_product_image_aspect_ratio() WC 11.1.2

private function resolve_product_image_aspect_ratio( $block ) {
	$attributes = $this->get_product_image_attributes( $block->inner_blocks );

	if ( empty( $attributes ) ) {
		return null;
	}

	if ( ! empty( $attributes['style']['dimensions']['aspectRatio'] ) ) {
		return $attributes['style']['dimensions']['aspectRatio'];
	}

	if ( ! empty( $attributes['aspectRatio'] ) ) {
		return $attributes['aspectRatio'];
	}

	$image_sizing = $attributes['imageSizing'] ?? 'single';

	if ( 'thumbnail' === $image_sizing || 'cropped' === $image_sizing ) {
		return $this->get_store_thumbnail_aspect_ratio();
	}

	return null;
}