diff --git a/libraries/src/Form/Field/CalendarField.php b/libraries/src/Form/Field/CalendarField.php index 0c776581af4e8..e4efa25f99466 100644 --- a/libraries/src/Form/Field/CalendarField.php +++ b/libraries/src/Form/Field/CalendarField.php @@ -281,52 +281,56 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) */ protected function getInput() { - $user = Factory::getApplication()->getIdentity(); + $user = Factory::getApplication()->getIdentity(); + $data = $this->collectLayoutData(); + $value = $data['value']; // If a known filter is given use it. switch (strtoupper($this->filter)) { case 'SERVER_UTC': // Convert a date to UTC based on the server timezone. - if ($this->value && $this->value != $this->getDatabase()->getNullDate()) { + if ($value && $value != $this->getDatabase()->getNullDate()) { // Get a date object based on the correct timezone. - $date = Factory::getDate($this->value, 'UTC'); + $date = Factory::getDate($value, 'UTC'); $date->setTimezone(new \DateTimeZone(Factory::getApplication()->get('offset'))); // Transform the date string. - $this->value = $date->format('Y-m-d H:i:s', true, false); + $value = $date->format('Y-m-d H:i:s', true, false); } break; case 'USER_UTC': // Convert a date to UTC based on the user timezone. - if ($this->value && $this->value != $this->getDatabase()->getNullDate()) { + if ($value && $value != $this->getDatabase()->getNullDate()) { // Get a date object based on the correct timezone. - $date = Factory::getDate($this->value, 'UTC'); + $date = Factory::getDate($value, 'UTC'); $date->setTimezone($user->getTimezone()); // Transform the date string. - $this->value = $date->format('Y-m-d H:i:s', true, false); + $value = $date->format('Y-m-d H:i:s', true, false); } break; } // Format value when not nulldate ('0000-00-00 00:00:00'), otherwise blank it as it would result in 1970-01-01. - if ($this->value && $this->value != $this->getDatabase()->getNullDate() && strtotime($this->value) !== false) { + if ($value && $value != $this->getDatabase()->getNullDate() && strtotime($value) !== false) { $tz = date_default_timezone_get(); date_default_timezone_set('UTC'); if ($this->filterFormat) { - $date = \DateTimeImmutable::createFromFormat('U', strtotime($this->value)); - $this->value = $date->format($this->filterFormat); + $date = \DateTimeImmutable::createFromFormat('U', strtotime($value)); + $value = $date->format($this->filterFormat); } else { - $this->value = strftime($this->format, strtotime($this->value)); + $value = strftime($this->format, strtotime($value)); } date_default_timezone_set($tz); } else { - $this->value = ''; + $value = ''; } - return $this->getRenderer($this->layout)->render($this->collectLayoutData()); + $data['value'] = $value; + + return $this->getRenderer($this->layout)->render($data); } /**