function DateTimeTimeAgoFormatter::viewElements

Same name in other branches
  1. 9 core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeTimeAgoFormatter.php \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeTimeAgoFormatter::viewElements()
  2. 8.9.x core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeTimeAgoFormatter.php \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeTimeAgoFormatter::viewElements()
  3. 10 core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeTimeAgoFormatter.php \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeTimeAgoFormatter::viewElements()

Overrides TimestampAgoFormatter::viewElements

File

core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeTimeAgoFormatter.php, line 26

Class

DateTimeTimeAgoFormatter
Plugin implementation of the 'Time ago' formatter for 'datetime' fields.

Namespace

Drupal\datetime\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
    $elements = [];
    foreach ($items as $delta => $item) {
        $date = $item->date;
        $output = [];
        if (!empty($item->date)) {
            $output = $this->formatDate($date);
        }
        $elements[$delta] = $output;
    }
    return $elements;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.