core/lib/Drupal/Core/Entity/ContentEntityBase.php | 3 +-- core/lib/Drupal/Core/Entity/Entity.php | 3 +-- core/lib/Drupal/Core/Entity/EntityViewBuilder.php | 12 ++++++------ core/modules/language/src/Config/LanguageConfigOverride.php | 4 ++-- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index ae8c2a5..5d9f7eb 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -996,8 +996,7 @@ public function referencedEntities() { * optimize this compared to \Drupal\Core\Entity\Entity::getCacheContexts(). */ public function getCacheContexts() { - // @todo use 'languages:content', blocked on https://www.drupal.org/node/2432837 - return count($this->getTranslationLanguages()) > 1 ? ['language'] : []; + return count($this->getTranslationLanguages()) > 1 ? ['languages:' . LanguageInterface::TYPE_CONTENT] : []; } /** diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index bbee272..d5ac2a4 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -431,8 +431,7 @@ public function referencedEntities() { * {@inheritdoc} */ public function getCacheContexts() { - // @todo use 'languages:content', blocked on https://www.drupal.org/node/2432837 - return ($this instanceof TranslatableInterface && count($this->getTranslationLanguages()) > 1) ? ['language'] : []; + return ($this instanceof TranslatableInterface && count($this->getTranslationLanguages()) > 1) ? ['languages:' . LanguageInterface::TYPE_CONTENT] : []; } /** diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index 0a8fdbb..4024537 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -198,15 +198,15 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langco // There are two cases: // 1. $langcode is the negotiated content language. Then $langcode matches - // the 'language' cache context, which is set by translated entities. - // Hence no work is necessary in this case. + // the "content language" cache context, which is set by translated + // entities. Hence no work is necessary in this case. // 2. $langcode is set to a specific value when calling ::view() or // ::viewMultiple() and therefore doesn't match the negotiated content - // language. In that case, the 'language' cache context set by the - // entity would be *wrong*. Thus, the 'language' cache context is - // removed and a cache key is added instead. + // language. In that case, the "content language" cache context set by + // the entity would be *wrong*. Thus, the "content language" cache + // context is removed and a cache key is added instead. if ($langcode !== $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId()) { - $build['#cache']['contexts'] = array_diff($build['#cache']['contexts'], ['language']); + $build['#cache']['contexts'] = array_diff($build['#cache']['contexts'], ['languages:' . LanguageInterface::TYPE_CONTENT]); $build['#cache']['keys'][] = 'forced-' . $langcode; } } diff --git a/core/modules/language/src/Config/LanguageConfigOverride.php b/core/modules/language/src/Config/LanguageConfigOverride.php index c13725f..d15bf70 100644 --- a/core/modules/language/src/Config/LanguageConfigOverride.php +++ b/core/modules/language/src/Config/LanguageConfigOverride.php @@ -11,6 +11,7 @@ use Drupal\Core\Config\StorableConfigBase; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Config\TypedConfigManagerInterface; +use Drupal\Core\Language\LanguageInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** @@ -96,8 +97,7 @@ public function getLangcode() { * {@inheritdoc} */ public function getCacheContexts() { - // @todo use 'languages:interface', blocked on https://www.drupal.org/node/2432837 - return ['language']; + return ['languages' . LanguageInterface::TYPE_INTERFACE]; } }