You are here

public function HtmlFieldFormatterTimestamp::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 TimestampFormatter::viewElements

File

src/Plugin/Field/FieldFormatter/HtmlFieldFormatterTimestamp.php, line 59

Class

HtmlFieldFormatterTimestamp
Plugin implementation of the 'timestamp' 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['#markup'], $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;
}