diff --git a/core/lib/Drupal/Core/Datetime/Element/DateElementBase.php b/core/lib/Drupal/Core/Datetime/Element/DateElementBase.php index 12ab03b..b516249 100644 --- a/core/lib/Drupal/Core/Datetime/Element/DateElementBase.php +++ b/core/lib/Drupal/Core/Datetime/Element/DateElementBase.php @@ -3,6 +3,7 @@ namespace Drupal\Core\Datetime\Element; use Drupal\Core\Datetime\DrupalDateTime; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element\FormElement; /** @@ -69,4 +70,31 @@ protected static function datetimeRangeYears($string, $date = NULL) { return array($min_year, $max_year); } + /** + * Perform common element processing for date related form elements. + * + * @param array $element + * The form element whose value is being processed. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The current state of the form. + * @param array $complete_form + * The complete form structure. + * + * @return array + * The form element whose value has been processed. + */ + public static function processDateElement(&$element, FormStateInterface $form_state, &$complete_form) { + // The value callback has populated the #value array. + $date = !empty($element['#value']['object']) ? $element['#value']['object'] : NULL; + + // Set a fallback timezone. + if ($date instanceof DrupalDateTime) { + $element['#date_timezone'] = $date->getTimezone()->getName(); + } + elseif (empty($element['#date_timezone'])) { + $element['#date_timezone'] = drupal_get_user_timezone(); + } + + return $element; + } } diff --git a/core/lib/Drupal/Core/Datetime/Element/Datelist.php b/core/lib/Drupal/Core/Datetime/Element/Datelist.php index ba8f6ba..2661ccf 100644 --- a/core/lib/Drupal/Core/Datetime/Element/Datelist.php +++ b/core/lib/Drupal/Core/Datetime/Element/Datelist.php @@ -25,6 +25,7 @@ public function getInfo() { array($class, 'validateDatelist'), ), '#process' => array( + array($class, 'processDateElement'), array($class, 'processDatelist'), ), '#theme' => 'datetime_form', @@ -183,14 +184,6 @@ public static function processDatelist(&$element, FormStateInterface $form_state // The value callback has populated the #value array. $date = !empty($element['#value']['object']) ? $element['#value']['object'] : NULL; - // Set a fallback timezone. - if ($date instanceof DrupalDateTime) { - $element['#date_timezone'] = $date->getTimezone()->getName(); - } - elseif (empty($element['#date_timezone'])) { - $element['#date_timezone'] = drupal_get_user_timezone(); - } - $element['#tree'] = TRUE; // Determine the order of the date elements. diff --git a/core/lib/Drupal/Core/Datetime/Element/Datetime.php b/core/lib/Drupal/Core/Datetime/Element/Datetime.php index 3015e2d..779f3f2 100644 --- a/core/lib/Drupal/Core/Datetime/Element/Datetime.php +++ b/core/lib/Drupal/Core/Datetime/Element/Datetime.php @@ -44,6 +44,7 @@ public function getInfo() { array($class, 'validateDatetime'), ), '#process' => array( + array($class, 'processDateElement'), array($class, 'processDatetime'), array($class, 'processGroup'), ), @@ -217,14 +218,6 @@ public static function processDatetime(&$element, FormStateInterface $form_state // The value callback has populated the #value array. $date = !empty($element['#value']['object']) ? $element['#value']['object'] : NULL; - // Set a fallback timezone. - if ($date instanceof DrupalDateTime) { - $element['#date_timezone'] = $date->getTimezone()->getName(); - } - elseif (empty($element['#date_timezone'])) { - $element['#date_timezone'] = drupal_get_user_timezone(); - } - $element['#tree'] = TRUE; if ($element['#date_date_element'] != 'none') {