You are here

protected function DateTimeDayDefaultFormatter::buildTimeWithAttribute in Date time day 8

Creates a render array from a date object with time attribute.

Parameters

\Drupal\Core\Datetime\DrupalDateTime $dateTime: A date object.

Return value

array A render array.

File

src/Plugin/Field/FieldFormatter/DateTimeDayDefaultFormatter.php, line 124

Class

DateTimeDayDefaultFormatter
Plugin implementation of the 'Default' formatter for 'datetimeday' fields.

Namespace

Drupal\date_time_day\Plugin\Field\FieldFormatter

Code

protected function buildTimeWithAttribute(DrupalDateTime $dateTime) {
  $build = [
    '#theme' => 'time',
    '#text' => $this
      ->formatTime($dateTime),
    '#html' => FALSE,
    '#attributes' => [
      'time' => $this
        ->formatTime($dateTime),
    ],
    '#cache' => [
      'contexts' => [
        'timezone',
      ],
    ],
  ];
  return $build;
}