function DateTimeRangeTrait::renderStartEndWithIsoAttribute

Same name in other branches
  1. 10 core/modules/datetime_range/src/DateTimeRangeTrait.php \Drupal\datetime_range\DateTimeRangeTrait::renderStartEndWithIsoAttribute()

Creates a render array with ISO attributes given start/end dates.

Parameters

\Drupal\Core\Datetime\DrupalDateTime $start_date: The start date to be rendered.

string $separator: The separator string.

\Drupal\Core\Datetime\DrupalDateTime $end_date: The end date to be rendered.

Return value

array A renderable array for a single date time range.

1 call to DateTimeRangeTrait::renderStartEndWithIsoAttribute()
DateTimeRangeTrait::viewElements in core/modules/datetime_range/src/DateTimeRangeTrait.php

File

core/modules/datetime_range/src/DateTimeRangeTrait.php, line 200

Class

DateTimeRangeTrait
Provides friendly methods for datetime range.

Namespace

Drupal\datetime_range

Code

protected function renderStartEndWithIsoAttribute(DrupalDateTime $start_date, string $separator, DrupalDateTime $end_date) : array {
    $element = [];
    if ($this->startDateIsDisplayed()) {
        $element[DateTimeRangeConstantsInterface::START_DATE] = $this->buildDateWithIsoAttribute($start_date);
    }
    if ($this->startDateIsDisplayed() && $this->endDateIsDisplayed()) {
        $element['separator'] = [
            '#plain_text' => ' ' . $separator . ' ',
        ];
    }
    if ($this->endDateIsDisplayed()) {
        $element[DateTimeRangeConstantsInterface::END_DATE] = $this->buildDateWithIsoAttribute($end_date);
    }
    return $element;
}

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