Automattic\WooCommerce\Blocks\BlockTypes
ProductImage::resolve_aspect_ratio
Resolve the aspect ratio for a product image.
Block-level overrides take priority over store thumbnail cropping settings.
Метод класса: ProductImage{}
Хуков нет.
Возвращает
string|null. CSS aspect ratio value, or null when no ratio should be applied.
Использование
// private - только в коде основоного (родительского) класса $result = $this->resolve_aspect_ratio( $attributes );
- $attributes(массив) (обязательный)
- Parsed block attributes.
Код ProductImage::resolve_aspect_ratio() ProductImage::resolve aspect ratio WC 11.3.0
private function resolve_aspect_ratio( $attributes ) {
if ( ! empty( $attributes['style']['dimensions']['aspectRatio'] ) ) {
return $attributes['style']['dimensions']['aspectRatio'];
}
if ( ! empty( $attributes['aspectRatio'] ) ) {
return $attributes['aspectRatio'];
}
// For backwards compatibility, we interpret "thumbnail" as following
// the store thumbnail cropping settings.
// "cropped" was used as a synonym for "thumbnail" in the past, but it's now deprecated.
if ( 'thumbnail' === $attributes['imageSizing'] || 'cropped' === $attributes['imageSizing'] ) {
return $this->get_store_thumbnail_aspect_ratio();
}
return null;
}