core/lib/Drupal/Core/Entity/EntityViewBuilder.php | 3 --- .../Field/Plugin/Field/FieldFormatter/TimestampFormatter.php | 9 ++++++++- .../src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php | 5 +++++ .../src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php | 9 ++++++++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index 2f506c2..af5abe0 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -185,9 +185,6 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langco 'contexts' => array( 'theme', 'user.roles', - // @todo Move this out of here and into field formatters that depend - // on the timezone. Blocked on https://drupal.org/node/2099137. - 'timezone', ), 'bin' => $this->cacheBin, ); diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampFormatter.php index 6861a00..6de42ee 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampFormatter.php @@ -31,7 +31,14 @@ public function viewElements(FieldItemListInterface $items) { $elements = array(); foreach ($items as $delta => $item) { - $elements[$delta] = array('#markup' => format_date($item->value)); + $elements[$delta] = [ + '#cache' => [ + 'contexts' => [ + 'timezone', + ], + ], + '#markup' => format_date($item->value) + ]; } return $elements; diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php index f983c8d..a7cb32a 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php @@ -127,6 +127,11 @@ public function viewElements(FieldItemListInterface $items) { // Display the date using theme datetime. $elements[$delta] = array( + '#cache' => [ + 'contexts' => [ + 'timezone', + ], + ], '#theme' => 'time', '#text' => $formatted_date, '#html' => FALSE, diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php index 24fc69c..3f68a7f 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php @@ -46,7 +46,14 @@ public function viewElements(FieldItemListInterface $items) { } $output = $date->format($format); } - $elements[$delta] = array('#markup' => $output); + $elements[$delta] = [ + '#cache' => [ + 'contexts' => [ + 'timezone', + ], + ], + '#markup' => $output, + ]; } return $elements;