protected function AddtocalView::buildDate in Add to Cal 8
Creates a render array from a date object.
Parameters
\Drupal\Core\Datetime\DrupalDateTime $date: A date object.
Return value
array A render array.
Overrides DateTimeFormatterBase::buildDate
1 call to AddtocalView::buildDate()
- AddtocalView::viewElements in src/
Plugin/ Field/ FieldFormatter/ AddtocalView.php - Builds a renderable array for a field value.
File
- src/
Plugin/ Field/ FieldFormatter/ AddtocalView.php, line 218
Class
- AddtocalView
- Plugin annotation @FieldFormatter( id = "addtocal_view", label = @Translation("Add to Cal"), field_types = { "date", "datestamp", "datetime", "daterange", } )
Namespace
Drupal\addtocal\Plugin\Field\FieldFormatterCode
protected function buildDate(DrupalDateTime $date) {
if ($this
->getFieldSetting('datetime_type') == DateTimeItem::DATETIME_TYPE_DATE) {
// A date without time will pick up the current time, use the default.
$date
->setDefaultDateTime();
}
$this
->setTimeZone($date);
$build = [
'#plain_text' => $this
->formatDate($date),
'#cache' => [
'contexts' => [
'timezone',
],
],
];
return $build;
}