You are here

protected function ProductBundleItemsWidget::getAttributeValues in Commerce Product Bundle 8

Gets the attribute values of a given set of variations.

Parameters

\Drupal\commerce_product\Entity\ProductVariationInterface[] $variations: The variations.

string $field_name: The field name of the attribute.

callable|null $callback: An optional callback to use for filtering the list.

Return value

array[] The attribute values, keyed by attribute ID.

1 call to ProductBundleItemsWidget::getAttributeValues()
ProductBundleItemsWidget::getItemAttributeInfo in src/Plugin/Field/FieldWidget/ProductBundleItemsWidget.php
Gets the attribute information for the selected product variation.

File

src/Plugin/Field/FieldWidget/ProductBundleItemsWidget.php, line 371

Class

ProductBundleItemsWidget
Plugin implementation of the 'commerce_product_bundle_items' widget.

Namespace

Drupal\commerce_product_bundle\Plugin\Field\FieldWidget

Code

protected function getAttributeValues(array $variations, $field_name, callable $callback = NULL) {
  $values = [];
  foreach ($variations as $variation) {
    if (is_null($callback) || call_user_func($callback, $variation)) {
      $attribute_value = $variation
        ->getAttributeValue($field_name);
      if ($attribute_value) {
        $values[$attribute_value
          ->id()] = $attribute_value
          ->label();
      }
      else {
        $values['_none'] = '';
      }
    }
  }
  return $values;
}