function DateTimePlainFormatter::viewElements

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

Overrides DateTimeFormatterBase::viewElements

File

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

Class

DateTimePlainFormatter
Plugin implementation of the 'Plain' formatter for 'datetime' fields.

Namespace

Drupal\datetime\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
    $elements = [];
    foreach ($items as $delta => $item) {
        if (!empty($item->date)) {
            
            /** @var \Drupal\Core\Datetime\DrupalDateTime $date */
            $date = $item->date;
            $elements[$delta] = $this->buildDate($date);
        }
    }
    return $elements;
}

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