- Issue created by @joachim
- 🇬🇧United Kingdom joachim
This affects https://www.drupal.org/project/action_link → , for example - outputting a date field action link in the same place as the controlled date field is rendered (such as in a view) makes the link broken, because it gets the wrong date value from the entity field.
- 🇮🇳India yogen.prasad
I debug this issue and this is the root cause for the issue:
File: DateTimeFormatterBase.php
protected function buildDateWithIsoAttribute(DrupalDateTime $date) { // Create the ISO date in Universal Time. $iso_date = $date->format("Y-m-d\TH:i:s") . 'Z'; $this->setTimeZone($date); $build = [ '#theme' => 'time', '#text' => $this->formatDate($date), '#attributes' => [ 'datetime' => $iso_date, ], '#cache' => [ 'contexts' => [ 'timezone', ], ], ]; return $build; }
here line $this->setTimeZone($date);
is the reason for saving the invalid date. - 🇬🇧United Kingdom joachim
Thanks!
I can confirm that if I replace the two calls to setTimeZone() in DateTimeFormatterBase with:
$clone = clone($date); $this->setTimeZone($clone);
then the problem is fixed.
I don't think that's the way to fix it though, as a child class might also call setTimeZone() and cause the same problem.
We probably need to remove setTimeZone() and replace it with a method which returns a cloned date rather than modifies the original.
- Open on Drupal.org →Environment: PHP 8.1 & MySQL 5.7
18:16 18:16 Queueing - @yogenprasad opened merge request.