From 8e9f1b61208087991afb783bd7d920f1e39fbcae Mon Sep 17 00:00:00 2001 From: effulgentsia Date: Wed, 20 Dec 2017 09:53:54 -0800 Subject: [PATCH] Issue #2929496 by plach, hchonov, timmillwood, catch, Wim Leers, amateescu, Calystod, andypost: Add dedicated interfaces to group methods dealing with revision translation and clean up the related documentation --- .../Core/Entity/ContentEntityInterface.php | 67 +------------------ .../Entity/ContentEntityStorageInterface.php | 19 +----- .../Core/Entity/Entity/EntityViewDisplay.php | 4 +- .../Drupal/Core/Entity/EntityRepository.php | 4 +- .../Drupal/Core/Entity/EntityViewBuilder.php | 4 +- .../Core/Entity/TranslatableInterface.php | 20 ++++++ .../TranslatableRevisionableInterface.php | 65 ++++++++++++++++++ ...anslatableRevisionableStorageInterface.php | 9 +++ .../Entity/TranslatableStorageInterface.php | 30 +++++++++ core/lib/Drupal/Core/Entity/entity.api.php | 66 +++++++++++++++--- 10 files changed, 187 insertions(+), 101 deletions(-) create mode 100644 core/lib/Drupal/Core/Entity/TranslatableInterface.php create mode 100644 core/lib/Drupal/Core/Entity/TranslatableRevisionableInterface.php create mode 100644 core/lib/Drupal/Core/Entity/TranslatableRevisionableStorageInterface.php create mode 100644 core/lib/Drupal/Core/Entity/TranslatableStorageInterface.php diff --git a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php index 3053d23694d..f43bc3b453d 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php @@ -2,8 +2,6 @@ namespace Drupal\Core\Entity; -use Drupal\Core\TypedData\TranslatableInterface; - /** * Defines a common interface for all content entity objects. * @@ -20,70 +18,7 @@ use Drupal\Core\TypedData\TranslatableInterface; * * @ingroup entity_api */ -interface ContentEntityInterface extends \Traversable, FieldableEntityInterface, RevisionableInterface, TranslatableInterface { - - /** - * Determines if the current translation of the entity has unsaved changes. - * - * @return bool - * TRUE if the current translation of the entity has changes. - */ - public function hasTranslationChanges(); - - /** - * Marks the current revision translation as affected. - * - * Setting the revision translation affected flag through the setter or - * through the field directly will always enforce it, which will be used by - * the entity storage to determine if the flag should be recomputed or the set - * value should be used instead. - * @see \Drupal\Core\Entity\ContentEntityStorageBase::populateAffectedRevisionTranslations() - * - * @param bool|null $affected - * The flag value. A NULL value can be specified to reset the current value - * and make sure a new value will be computed by the system. - * - * @return $this - */ - public function setRevisionTranslationAffected($affected); - - /** - * Checks whether the current translation is affected by the current revision. - * - * @return bool - * TRUE if the entity object is affected by the current revision, FALSE - * otherwise. - */ - public function isRevisionTranslationAffected(); - - /** - * Checks if the revision translation affected flag value has been enforced. - * - * @return bool - * TRUE if revision translation affected flag is enforced, FALSE otherwise. - * - * @internal - */ - public function isRevisionTranslationAffectedEnforced(); - - /** - * Enforces the revision translation affected flag value. - * - * Note that this method call will not have any influence on the storage if - * the value of the revision translation affected flag is NULL which is used - * as an indication for the storage to recompute the flag. - * @see \Drupal\Core\Entity\ContentEntityInterface::setRevisionTranslationAffected() - * - * @param bool $enforced - * If TRUE, the value of the revision translation affected flag will be - * enforced so that on entity save the entity storage will not recompute it. - * Otherwise the storage will recompute it. - * - * @return $this - * - * @internal - */ - public function setRevisionTranslationAffectedEnforced($enforced); +interface ContentEntityInterface extends \Traversable, FieldableEntityInterface, TranslatableRevisionableInterface { /** * Gets the loaded Revision ID of the entity. diff --git a/core/lib/Drupal/Core/Entity/ContentEntityStorageInterface.php b/core/lib/Drupal/Core/Entity/ContentEntityStorageInterface.php index 678937bdc00..9b35a84bef1 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityStorageInterface.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityStorageInterface.php @@ -5,24 +5,7 @@ namespace Drupal\Core\Entity; /** * A storage that supports content entity types. */ -interface ContentEntityStorageInterface extends EntityStorageInterface, RevisionableStorageInterface { - - /** - * Constructs a new entity translation object, without permanently saving it. - * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity - * The entity object being translated. - * @param string $langcode - * The translation language code. - * @param array $values - * (optional) An associative array of initial field values keyed by field - * name. If none is provided default values will be applied. - * - * @return \Drupal\Core\Entity\ContentEntityInterface - * A new entity translation object. - */ - public function createTranslation(ContentEntityInterface $entity, $langcode, array $values = []); - +interface ContentEntityStorageInterface extends EntityStorageInterface, TranslatableRevisionableStorageInterface { /** * Creates an entity with sample field values. diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php index 1604e311132..7c7d62e04da 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php @@ -8,7 +8,7 @@ use Drupal\Core\Entity\EntityDisplayPluginCollection; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\EntityDisplayBase; -use Drupal\Core\TypedData\TranslatableInterface; +use Drupal\Core\TypedData\TranslatableInterface as TranslatableDataInterface; /** * Configuration entity that contains display options for all components of a @@ -253,7 +253,7 @@ class EntityViewDisplay extends EntityDisplayBase implements EntityViewDisplayIn // those values using: // - the entity language if the entity is translatable, // - the current "content language" otherwise. - if ($entity instanceof TranslatableInterface && $entity->isTranslatable()) { + if ($entity instanceof TranslatableDataInterface && $entity->isTranslatable()) { $view_langcode = $entity->language()->getId(); } else { diff --git a/core/lib/Drupal/Core/Entity/EntityRepository.php b/core/lib/Drupal/Core/Entity/EntityRepository.php index 986cc50b543..37a89d793eb 100644 --- a/core/lib/Drupal/Core/Entity/EntityRepository.php +++ b/core/lib/Drupal/Core/Entity/EntityRepository.php @@ -5,7 +5,7 @@ namespace Drupal\Core\Entity; use Drupal\Core\Config\Entity\ConfigEntityTypeInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageManagerInterface; -use Drupal\Core\TypedData\TranslatableInterface; +use Drupal\Core\TypedData\TranslatableInterface as TranslatableDataInterface; /** * Provides several mechanisms for retrieving entities. @@ -82,7 +82,7 @@ class EntityRepository implements EntityRepositoryInterface { public function getTranslationFromContext(EntityInterface $entity, $langcode = NULL, $context = []) { $translation = $entity; - if ($entity instanceof TranslatableInterface && count($entity->getTranslationLanguages()) > 1) { + if ($entity instanceof TranslatableDataInterface && count($entity->getTranslationLanguages()) > 1) { if (empty($langcode)) { $langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId(); $entity->addCacheContexts(['languages:' . LanguageInterface::TYPE_CONTENT]); diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index e95c01b2c84..faeb1473df4 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -11,7 +11,7 @@ use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Render\Element; use Drupal\Core\Theme\Registry; -use Drupal\Core\TypedData\TranslatableInterface; +use Drupal\Core\TypedData\TranslatableInterface as TranslatableDataInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -189,7 +189,7 @@ class EntityViewBuilder extends EntityHandlerBase implements EntityHandlerInterf 'bin' => $this->cacheBin, ]; - if ($entity instanceof TranslatableInterface && count($entity->getTranslationLanguages()) > 1) { + if ($entity instanceof TranslatableDataInterface && count($entity->getTranslationLanguages()) > 1) { $build['#cache']['keys'][] = $entity->language()->getId(); } } diff --git a/core/lib/Drupal/Core/Entity/TranslatableInterface.php b/core/lib/Drupal/Core/Entity/TranslatableInterface.php new file mode 100644 index 00000000000..573310b6c2c --- /dev/null +++ b/core/lib/Drupal/Core/Entity/TranslatableInterface.php @@ -0,0 +1,20 @@ +