Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions modules/product/commerce_product.module
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ function commerce_product_theme() {
'commerce_product_variation' => [
'render element' => 'elements',
],
'commerce_product_attribute_value' => [
'render element' => 'elements',
],
];
}

Expand All @@ -81,6 +84,13 @@ function commerce_product_theme_suggestions_commerce_product_variation(array $va
return _commerce_entity_theme_suggestions('commerce_product_variation', $variables);
}

/**
* Implements hook_theme_suggestions_commerce_product_commerce_product_attribute_value().
*/
function commerce_product_theme_suggestions_commerce_product_attribute_value(array $variables) {
return _commerce_entity_theme_suggestions('commerce_product_attribute_value', $variables);
}

/**
* Prepares variables for product templates.
*
Expand Down Expand Up @@ -129,6 +139,28 @@ function template_preprocess_commerce_product_variation(array &$variables) {
}
}

/**
* Prepares variables for product attribute value templates.
*
* Default template: commerce-product-attribute-value.html.twig.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing rendered fields.
* - attributes: HTML attributes for the containing element.
*/
function template_preprocess_commerce_product_commerce_product_attribute_value(array &$variables) {
/** @var Drupal\commerce_product\Entity\ProductAttributeValueInterface $product */
$attribute_value = $variables['elements']['#commerce_product_attribute_value'];

$variables['attribute_value'] = $attribute_value;
// Helpful $content variable for templates.
$variables['content'] = [];
foreach (\Drupal\Core\Render\Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}

/**
* Adds the default stores field to a product.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{#
/**
* @file
*
* Default theme implementation for product attribute values.
*
* Available variables:
* - content: Items for the content of the product attribute value.
* Use 'content' to print them all, or print a subset such as
* 'content.sku'. Use the following code to exclude the
* printing of a given child element:
* @code
* {{ content|without('name') }}
* @endcode
* - attributes: HTML attributes for the wrapper.
* - attribute_value: The product attribute value object.
*
* @ingroup themeable
*/
#}
<div{{ attributes}}>
{{- content.attribute_value -}}
{% if content %}
{{- content -}}
{% endif %}
</div>