function DateTimeRangeTrait::renderStartEnd
Same name in other branches
- 10 core/modules/datetime_range/src/DateTimeRangeTrait.php \Drupal\datetime_range\DateTimeRangeTrait::renderStartEnd()
Creates a render array 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.
2 calls to DateTimeRangeTrait::renderStartEnd()
- 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.
File
-
core/
modules/ datetime_range/ src/ DateTimeRangeTrait.php, line 173
Class
- DateTimeRangeTrait
- Provides friendly methods for datetime range.
Namespace
Drupal\datetime_rangeCode
protected function renderStartEnd(DrupalDateTime $start_date, string $separator, DrupalDateTime $end_date) : array {
$element = [];
if ($this->startDateIsDisplayed()) {
$element[DateTimeRangeConstantsInterface::START_DATE] = $this->buildDate($start_date);
}
if ($this->startDateIsDisplayed() && $this->endDateIsDisplayed()) {
$element['separator'] = [
'#plain_text' => ' ' . $separator . ' ',
];
}
if ($this->endDateIsDisplayed()) {
$element[DateTimeRangeConstantsInterface::END_DATE] = $this->buildDate($end_date);
}
return $element;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.