You are here

protected function AddToCart::renderPreparedAttributes in Commerce Cart Flyout 8

Renders the prepared attributes.

Parameters

array $prepared_attributes: The prepared attributed.

Return value

array The array of rendered prepated attributes.

1 call to AddToCart::renderPreparedAttributes()
AddToCart::viewElements in src/Plugin/Field/FieldFormatter/AddToCart.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/AddToCart.php, line 293

Class

AddToCart
Plugin implementation of the 'commerce_cart_flyout_add_to_cart' formatter.

Namespace

Drupal\commerce_cart_flyout\Plugin\Field\FieldFormatter

Code

protected function renderPreparedAttributes(array $prepared_attributes) {
  return array_map(function (PreparedAttribute $attribute) {
    return array_map(function ($attribute_value_id) {
      $attribute_value = $this->attributeValueStorage
        ->load($attribute_value_id);
      $attribute_value_build = $this->attributeValueViewBuilder
        ->view($attribute_value, 'add_to_cart');
      return [
        'output' => $this->renderer
          ->render($attribute_value_build),
        'attribute_value_id' => $attribute_value_id,
      ];
    }, array_keys($attribute
      ->getValues()));
  }, $this
    ->filterPreparedAttributedByElementType($prepared_attributes, 'commerce_product_rendered_attribute'));
}