function DateTimeFormatterBase::buildDate

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

Creates a render array from a date object.

Parameters

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

Return value

array A render array.

4 calls to DateTimeFormatterBase::buildDate()
DateRangeCustomFormatter::viewElements in core/modules/datetime_range/src/Plugin/Field/FieldFormatter/DateRangeCustomFormatter.php
Builds a renderable array for a field value.
DateRangePlainFormatter::viewElements in core/modules/datetime_range/src/Plugin/Field/FieldFormatter/DateRangePlainFormatter.php
Builds a renderable array for a field value.
DateTimeCustomFormatter::viewElements in core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php
Builds a renderable array for a field value.
DateTimePlainFormatter::viewElements in core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php
Builds a renderable array for a field value.

File

core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php, line 202

Class

DateTimeFormatterBase
Base class for 'DateTime Field formatter' plugin implementations.

Namespace

Drupal\datetime\Plugin\Field\FieldFormatter

Code

protected function buildDate(DrupalDateTime $date) {
    $this->setTimeZone($date);
    $build = [
        '#markup' => $this->formatDate($date),
        '#cache' => [
            'contexts' => [
                'timezone',
            ],
        ],
    ];
    return $build;
}

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