protected function ProductAttributesOverview::getAttributeItemList in Commerce Core 8.2
Gets the renderable item list of attributes.
Parameters
\Drupal\Core\Field\FieldItemListInterface $variation_items: The item list of variation entities.
\Drupal\commerce_product\Entity\ProductAttributeInterface $attribute: The product attribute.
Return value
array The render array.
1 call to ProductAttributesOverview::getAttributeItemList()
- ProductAttributesOverview::viewElements in modules/
product/ src/ Plugin/ Field/ FieldFormatter/ ProductAttributesOverview.php - Builds a renderable array for a field value.
File
- modules/
product/ src/ Plugin/ Field/ FieldFormatter/ ProductAttributesOverview.php, line 209
Class
- ProductAttributesOverview
- Plugin implementation of the 'commerce_product_attributes_overview' formatter.
Namespace
Drupal\commerce_product\Plugin\Field\FieldFormatterCode
protected function getAttributeItemList(FieldItemListInterface $variation_items, ProductAttributeInterface $attribute) {
$build = [
'#theme' => 'item_list',
'#title' => $attribute
->label(),
'#items' => [],
];
$view_builder = $this->entityTypeManager
->getViewBuilder('commerce_product_attribute_value');
/** @var \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem $variation */
foreach ($variation_items as $variation) {
/** @var \Drupal\commerce_product\Entity\ProductAttributeValueInterface $attribute_value */
$attribute_value = $variation->entity
->getAttributeValue('attribute_' . $attribute
->id());
// If this attribute value has already been added, skip.
if (isset($build['#items'][$attribute_value
->id()])) {
continue;
}
$attribute_render_array = $view_builder
->view($attribute_value, $this
->getSetting('view_mode'));
$attribute_build = $this->renderer
->render($attribute_render_array);
$attribute_build = Link::fromTextAndUrl($attribute_build, $variation_items
->getEntity()
->toUrl())
->toRenderable();
$build['#items'][$attribute_value
->id()] = $attribute_build;
}
return $build;
}