You are here

public function PaymentStatusOverview::viewElements in Payment 8.2

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 FormatterInterface::viewElements

File

src/Plugin/Field/FieldFormatter/PaymentStatusOverview.php, line 24

Class

PaymentStatusOverview
A payment status field formatter.

Namespace

Drupal\payment\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $payment_statuses = [];

  /** @var \Drupal\plugin\Plugin\Field\FieldType\PluginCollectionItemInterface $item */
  foreach ($items as $delta => $item) {
    $payment_statuses[$delta] = $item
      ->getContainedPluginInstance();
  }
  $build[0] = [
    '#payment_statuses' => $payment_statuses,
    '#type' => 'payment_statuses_display',
  ];
  return $build;
}