You are here

public function DateTimePlainFormatter::viewElements in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimePlainFormatter::viewElements()

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

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

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;
}