You are here

public function IntervalFormatterBase::viewElements in Interval Field 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 FormatterInterface::viewElements

2 methods override IntervalFormatterBase::viewElements()
IntervalFormatterPhp::viewElements in src/Plugin/Field/FieldFormatter/IntervalFormatterPhp.php
Builds a renderable array for a field value.
IntervalFormatterRaw::viewElements in src/Plugin/Field/FieldFormatter/IntervalFormatterRaw.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/IntervalFormatterBase.php, line 37

Class

IntervalFormatterBase
Provides a base formatter class for interval field formatters.

Namespace

Drupal\interval\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $element = [];
  foreach ($items as $delta => $item) {
    $element[$delta] = [
      '#type' => 'html_tag',
      '#attributes' => [
        'class' => [
          'interval-value',
        ],
      ],
      '#tag' => 'div',
      '#value' => $this
        ->formatInterval($item),
    ];
  }
  return $element;
}