You are here

public function PadoAddToCartFormatter::viewElements in Commerce Product Add-on 8

Builds a renderable array for a field value.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.

string $langcode: The language that should be used to render the field.

Return value

array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.

Overrides AddToCartFormatter::viewElements

File

src/Plugin/Field/FieldFormatter/PadoAddToCartFormatter.php, line 83

Class

PadoAddToCartFormatter
Plugin implementation of the 'commerce_pado_add_to_cart' formatter.

Namespace

Drupal\commerce_pado\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $elements = [];
  $elements[0]['add_to_cart_form'] = [
    '#lazy_builder' => [
      'commerce_pado.lazy_builders:addToCartWithAddOnsForm',
      [
        $items
          ->getEntity()
          ->id(),
        $this->viewMode,
        $this
          ->getSetting('combine'),
        $this
          ->getSetting('add_on_field'),
        $this
          ->getSetting('multiple'),
      ],
    ],
    '#create_placeholder' => TRUE,
  ];
  return $elements;
}