diff --git a/core/modules/datetime_range/src/DateTimeRangeTrait.php b/core/modules/datetime_range/src/DateTimeRangeTrait.php index daeca49..5a34f2c 100644 --- a/core/modules/datetime_range/src/DateTimeRangeTrait.php +++ b/core/modules/datetime_range/src/DateTimeRangeTrait.php @@ -2,6 +2,7 @@ namespace Drupal\datetime_range; +use Drupal\Core\Datetime\DrupalDateTime; use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem; /** @@ -18,15 +19,21 @@ * @return array * A render array. */ - protected function buildDate($date) { + 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. datetime_date_default_time($date); } $this->setTimeZone($date); - $build = ['#plain_text' => $this->formatDate($date)]; - $build['#cache']['contexts'][] = 'timezone'; + $build = [ + '#plain_text' => $this->formatDate($date), + '#cache' => [ + 'contexts' => [ + 'timezone', + ], + ], + ]; return $build; } @@ -40,7 +47,7 @@ protected function buildDate($date) { * @return array * A render array. */ - protected function buildDateWithIsoAttribute($date) { + protected function buildDateWithIsoAttribute(DrupalDateTime $date) { if ($this->getFieldSetting('datetime_type') == DateTimeItem::DATETIME_TYPE_DATE) { // A date without time will pick up the current time, use the default. datetime_date_default_time($date); @@ -58,8 +65,12 @@ protected function buildDateWithIsoAttribute($date) { '#attributes' => [ 'datetime' => $iso_date, ], + '#cache' => [ + 'contexts' => [ + 'timezone', + ], + ], ]; - $build['#cache']['contexts'][] = 'timezone'; return $build; } diff --git a/core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php b/core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php index 5e695b3..ae9f24a 100644 --- a/core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php +++ b/core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php @@ -124,7 +124,7 @@ public function massageFormValues(array $values, array $form, FormStateInterface * @param array $complete_form * The complete form structure. */ - public function validateStartEnd(&$element, FormStateInterface $form_state, &$complete_form) { + public function validateStartEnd(array &$element, FormStateInterface $form_state, array &$complete_form) { $start_date = $element['value']['#value']['object']; $end_date = $element['end_value']['#value']['object'];