function DateTimeCustomFormatter::viewElements

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

Overrides DateTimeFormatterBase::viewElements

File

core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php, line 35

Class

DateTimeCustomFormatter
Plugin implementation of the 'Custom' formatter for 'datetime' fields.

Namespace

Drupal\datetime\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
    // @todo Evaluate removing this method in
    // https://www.drupal.org/node/2793143 to determine if the behavior and
    // markup in the base class implementation can be used instead.
    $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.