diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index cab168b2b2..721bd9c5cd 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -349,8 +349,15 @@ public function setRevisionTranslationAffected($affected) { /** * {@inheritdoc} */ + public function setIsDefaultTranslation($is_default_translation) { + $this->isDefaultTranslation = $is_default_translation; + } + + /** + * {@inheritdoc} + */ public function isDefaultTranslation() { - if (isset($this->isDefaultTranslation)) { + if ($this->isDefaultTranslation !== NULL) { return $this->isDefaultTranslation; } return $this->activeLangcode === LanguageInterface::LANGCODE_DEFAULT; diff --git a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php index 815ea0bb73..210b7adaf6 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php @@ -485,13 +485,14 @@ protected function invokeFieldMethod($method, ContentEntityInterface $entity) { if ($method == 'postSave' && !empty($entity->original)) { $original_langcodes = array_keys($entity->original->getTranslationLanguages()); foreach (array_diff($original_langcodes, $langcodes) as $removed_langcode) { + /** @var \Drupal\Core\Entity\ContentEntityInterface $translation */ $translation = $entity->original->getTranslation($removed_langcode); // Fields may rely on the isDefaultTranslation() method to determine // what is going to be deleted - the whole entity or a particular // translation. if ($translation->isDefaultTranslation()) { - $translation->isDefaultTranslation = FALSE; + $translation->setIsDefaultTranslation(FALSE); } $fields = $translation->getTranslatableFields(); diff --git a/core/lib/Drupal/Core/TypedData/TranslatableInterface.php b/core/lib/Drupal/Core/TypedData/TranslatableInterface.php index 5b57a8717f..1e648f8558 100644 --- a/core/lib/Drupal/Core/TypedData/TranslatableInterface.php +++ b/core/lib/Drupal/Core/TypedData/TranslatableInterface.php @@ -16,6 +16,18 @@ public function language(); /** + * Overrides isDefaultTranslation() result. + * + * @param bool|null $is_default_translation + * If boolean value is passed, the value will override the result of + * isDefaultTranslation() method. If NULL is passed, the default logic will + * be used for determining the result. + * + * @internal + */ + public function setIsDefaultTranslation($is_default_translation); + + /** * Checks whether the translation is the default one. * * @return bool