You are here

public function HtmlFieldFormatterDateTime::viewElements in HTML Formatter 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 DateTimeFormatterBase::viewElements

File

src/Plugin/Field/FieldFormatter/HtmlFieldFormatterDateTime.php, line 58

Class

HtmlFieldFormatterDateTime
Plugin implementation of the 'datetime' html field formatter.

Namespace

Drupal\html_formatter\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $elements = parent::viewElements($items, $langcode);
  $url = $this
    ->getEntityUrl($items);
  foreach ($elements as $delta => $element) {
    $value = $this
      ->getLinkedValue($this->settings, $element['#text'], $url);
    $elements[$delta]['#theme'] = 'html_formatter';
    $elements[$delta]['#value'] = $value;
    $elements[$delta]['#tag'] = $this
      ->getSetting('tag');
    $elements[$delta]['#attributes']['class'] = $this
      ->getSetting('class');
  }
  return $elements;
}