function theme_uc_product_attributes in Ubercart 8.4
Same name and namespace in other branches
- 6.2 uc_attribute/uc_attribute.admin.inc \theme_uc_product_attributes()
- 7.3 uc_attribute/uc_attribute.admin.inc \theme_uc_product_attributes()
Returns a themed set of attribute options for use in order displays.
Parameters
array $variables: An associative array containing:
- attributes: An associative array containing the set of attributes,
with each element keyed by attribute ID:
- <aid>: An associative array containing:
- #attribute_name: Attribute name.
- #options: Array of option names.
- <aid>: An associative array containing:
Return value
string Themed set of attribute options.
1 string reference to 'theme_uc_product_attributes'
- uc_attribute_theme in uc_attribute/
uc_attribute.module - Implements hook_theme().
2 theme calls to theme_uc_product_attributes()
- hook_uc_product_description in uc_product/
uc_product.api.php - Returns a structured array representing the given product's description.
- uc_attribute_uc_product_description in uc_attribute/
uc_attribute.module - Implements hook_uc_product_description().
File
- uc_attribute/
uc_attribute.theme.inc, line 26 - Attribute theme functions.
Code
function theme_uc_product_attributes(array $variables) {
$attributes = $variables['attributes'];
$option_rows = [];
foreach (Element::children($attributes) as $key) {
$optionstr = '';
foreach ((array) $attributes[$key]['#options'] as $option) {
// We only need to allow translation from the second option onward.
if (empty($optionstr)) {
$optionstr .= $option;
}
else {
$optionstr .= t(', @option', [
'@option' => $option,
]);
}
}
if ($optionstr != '') {
$option_rows[$key] = t('@attribute: @option', [
'@attribute' => $attributes[$key]['#attribute_name'],
'@option' => $optionstr,
]);
}
}
if (!empty($option_rows)) {
$item_list = [
'#theme' => 'item_list',
'#items' => array_values($option_rows),
'#attributes' => [
'class' => [
'product-description',
],
],
];
return \Drupal::service('renderer')
->render($item_list);
}
return '';
}