Unverified Commit 094890e6 authored by larowlan's avatar larowlan
Browse files

Issue #2942907 by plach, amateescu, Berdir, tim.plunkett, hchonov,...

Issue #2942907 by plach, amateescu, Berdir, tim.plunkett, hchonov, gabesullice, jibran, xjm, tedbow, timmillwood, larowlan, Sam152, pmelab, catch, effulgentsia: Entity system does not provide an API for retrieving an entity variant that is safe for editing
parent 1036f4cc
......@@ -564,7 +564,7 @@ services:
arguments: ['@entity_type.manager', '@language_manager', '@module_handler', '@typed_data_manager', '@cache.discovery']
entity.repository:
class: Drupal\Core\Entity\EntityRepository
arguments: ['@entity_type.manager', '@language_manager']
arguments: ['@entity_type.manager', '@language_manager', '@context.repository']
entity_display.repository:
class: Drupal\Core\Entity\EntityDisplayRepository
arguments: ['@entity_type.manager', '@module_handler', '@cache.discovery', '@language_manager']
......@@ -1005,7 +1005,7 @@ services:
class: Drupal\Core\ParamConverter\EntityConverter
tags:
- { name: paramconverter }
arguments: ['@entity_type.manager', '@language_manager', '@entity.repository']
arguments: ['@entity_type.manager', '@entity.repository']
paramconverter.entity_revision:
class: Drupal\Core\ParamConverter\EntityRevisionParamConverter
tags:
......@@ -1016,7 +1016,7 @@ services:
tags:
# Use a higher priority than EntityConverter, see the class for details.
- { name: paramconverter, priority: 5 }
arguments: ['@entity_type.manager', '@config.factory', '@router.admin_context', '@language_manager', '@entity.repository']
arguments: ['@entity_type.manager', '@config.factory', '@router.admin_context', '@entity.repository']
lazy: true
route_subscriber.module:
class: Drupal\Core\EventSubscriber\ModuleRouteSubscriber
......
......@@ -380,6 +380,61 @@ public function getTranslationFromContext(EntityInterface $entity, $langcode = N
return $this->container->get('entity.repository')->getTranslationFromContext($entity, $langcode, $context);
}
/**
* {@inheritdoc}
*
* @deprecated in Drupal 8.7.0, will be removed before Drupal 9.0.0.
* Use \Drupal\Core\Entity\EntityRepositoryInterface::getActive() instead.
*
* @see https://www.drupal.org/node/2549139
*/
public function getActive($entity_type_id, $entity_id, array $contexts = NULL) {
@trigger_error('EntityManagerInterface::getActive() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityRepositoryInterface::getActive() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
return $this->container->get('entity.repository')->getActive($entity_type_id, $entity_id, $contexts);
}
/**
* {@inheritdoc}
*
* @deprecated in Drupal 8.7.0, will be removed before Drupal 9.0.0.
* Use \Drupal\Core\Entity\EntityRepositoryInterface::getActiveMultiple()
* instead.
*
* @see https://www.drupal.org/node/2549139
*/
public function getActiveMultiple($entity_type_id, array $entity_ids, array $contexts = NULL) {
@trigger_error('EntityManagerInterface::getActiveMultiple() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityRepositoryInterface::getActiveMultiple() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
return $this->container->get('entity.repository')->getActiveMultiple($entity_type_id, $entity_ids, $contexts);
}
/**
* {@inheritdoc}
*
* @deprecated in Drupal 8.7.0, will be removed before Drupal 9.0.0.
* Use \Drupal\Core\Entity\EntityRepositoryInterface::getCanonical()
* instead.
*
* @see https://www.drupal.org/node/2549139
*/
public function getCanonical($entity_type_id, $entity_id, array $contexts = NULL) {
@trigger_error('EntityManagerInterface::getCanonical() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityRepositoryInterface::getCanonical() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
return $this->container->get('entity.repository')->getCanonical($entity_type_id, $entity_id, $contexts);
}
/**
* {@inheritdoc}
*
* @deprecated in Drupal 8.7.0, will be removed before Drupal 9.0.0.
* Use \Drupal\Core\Entity\EntityRepositoryInterface::getCanonicalMultiple()
* instead.
*
* @see https://www.drupal.org/node/2549139
*/
public function getCanonicalMultiple($entity_type_id, array $entity_ids, array $contexts = NULL) {
@trigger_error('EntityManagerInterface::getCanonicalMultiple() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityRepositoryInterface::getCanonicalMultiple() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
return $this->container->get('entity.repository')->getCanonicalMultiple($entity_type_id, $entity_ids, $contexts);
}
/**
* {@inheritdoc}
*
......
......@@ -5,6 +5,7 @@
use Drupal\Core\Config\Entity\ConfigEntityTypeInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Plugin\Context\ContextRepositoryInterface;
use Drupal\Core\TypedData\TranslatableInterface as TranslatableDataInterface;
/**
......@@ -26,6 +27,13 @@ class EntityRepository implements EntityRepositoryInterface {
*/
protected $languageManager;
/**
* The context repository service.
*
* @var \Drupal\Core\Plugin\Context\ContextRepositoryInterface
*/
protected $contextRepository;
/**
* Constructs a new EntityRepository.
*
......@@ -33,10 +41,19 @@ class EntityRepository implements EntityRepositoryInterface {
* The entity type manager.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Plugin\Context\ContextRepositoryInterface $context_repository
* The context repository service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, LanguageManagerInterface $language_manager) {
public function __construct(EntityTypeManagerInterface $entity_type_manager, LanguageManagerInterface $language_manager, ContextRepositoryInterface $context_repository = NULL) {
$this->entityTypeManager = $entity_type_manager;
$this->languageManager = $language_manager;
if (isset($context_repository)) {
$this->contextRepository = $context_repository;
}
else {
@trigger_error('The context.repository service must be passed to EntityRepository::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2938929.', E_USER_DEPRECATED);
$this->contextRepository = \Drupal::service('context.repository');
}
}
/**
......@@ -112,4 +129,178 @@ public function getTranslationFromContext(EntityInterface $entity, $langcode = N
return $translation;
}
/**
* {@inheritdoc}
*/
public function getActive($entity_type_id, $entity_id, array $contexts = NULL) {
return current($this->getActiveMultiple($entity_type_id, [$entity_id], $contexts)) ?: NULL;
}
/**
* {@inheritdoc}
*/
public function getActiveMultiple($entity_type_id, array $entity_ids, array $contexts = NULL) {
$active = [];
if (!isset($contexts)) {
$contexts = $this->contextRepository->getAvailableContexts();
}
// @todo Consider implementing a more performant version of this logic fully
// supporting multiple entities in https://www.drupal.org/node/3031082.
$langcode = $this->languageManager->isMultilingual()
? $this->getContentLanguageFromContexts($contexts)
: $this->languageManager->getDefaultLanguage()->getId();
$entities = $this->entityTypeManager
->getStorage($entity_type_id)
->loadMultiple($entity_ids);
foreach ($entities as $id => $entity) {
// Retrieve the fittest revision, if needed.
if ($entity instanceof RevisionableInterface && $entity->getEntityType()->isRevisionable()) {
$entity = $this->getLatestTranslationAffectedRevision($entity, $langcode);
}
// Retrieve the fittest translation, if needed.
if ($entity instanceof TranslatableInterface) {
$entity = $this->getTranslationFromContext($entity, $langcode);
}
$active[$id] = $entity;
}
return $active;
}
/**
* {@inheritdoc}
*/
public function getCanonical($entity_type_id, $entity_id, array $contexts = NULL) {
return current($this->getCanonicalMultiple($entity_type_id, [$entity_id], $contexts)) ?: NULL;
}
/**
* {@inheritdoc}
*/
public function getCanonicalMultiple($entity_type_id, array $entity_ids, array $contexts = NULL) {
$entities = $this->entityTypeManager->getStorage($entity_type_id)
->loadMultiple($entity_ids);
if (!$entities || !$this->languageManager->isMultilingual()) {
return $entities;
}
if (!isset($contexts)) {
$contexts = $this->contextRepository->getAvailableContexts();
}
// @todo Consider deprecating the legacy context operation altogether in
// https://www.drupal.org/node/3031124.
$legacy_context = [];
$key = static::CONTEXT_ID_LEGACY_CONTEXT_OPERATION;
if (isset($contexts[$key])) {
$legacy_context['operation'] = $contexts[$key]->getContextValue();
}
$canonical = [];
$langcode = $this->getContentLanguageFromContexts($contexts);
foreach ($entities as $id => $entity) {
$canonical[$id] = $this->getTranslationFromContext($entity, $langcode, $legacy_context);
}
return $canonical;
}
/**
* Retrieves the current content language from the specified contexts.
*
* @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
* An array of context items.
*
* @return string|null
* A language code or NULL if no language context was provided.
*/
protected function getContentLanguageFromContexts(array $contexts) {
// Content language might not be configurable, in which case we need to fall
// back to a configurable language type.
foreach ([LanguageInterface::TYPE_CONTENT, LanguageInterface::TYPE_INTERFACE] as $language_type) {
$context_id = '@language.current_language_context:' . $language_type;
if (isset($contexts[$context_id])) {
return $contexts[$context_id]->getContextValue()->getId();
}
}
return $this->languageManager->getDefaultLanguage()->getId();
}
/**
* Returns the latest revision translation of the specified entity.
*
* @param \Drupal\Core\Entity\RevisionableInterface $entity
* The default revision of the entity being converted.
* @param string $langcode
* The language of the revision translation to be loaded.
*
* @return \Drupal\Core\Entity\RevisionableInterface
* The latest translation-affecting revision for the specified entity, or
* just the latest revision, if the specified entity is not translatable or
* does not have a matching translation yet.
*/
protected function getLatestTranslationAffectedRevision(RevisionableInterface $entity, $langcode) {
$revision = NULL;
$storage = $this->entityTypeManager->getStorage($entity->getEntityTypeId());
if ($entity instanceof TranslatableRevisionableInterface && $entity->isTranslatable()) {
/** @var \Drupal\Core\Entity\TranslatableRevisionableStorageInterface $storage */
$revision_id = $storage->getLatestTranslationAffectedRevisionId($entity->id(), $langcode);
// If the latest translation-affecting revision was a default revision, it
// is fine to load the latest revision instead, because in this case the
// latest revision, regardless of it being default or pending, will always
// contain the most up-to-date values for the specified translation. This
// provides a BC behavior when the route is defined by a module always
// expecting the latest revision to be loaded and to be the default
// revision. In this particular case the latest revision is always going
// to be the default revision, since pending revisions would not be
// supported.
$revision = $revision_id ? $this->loadRevision($entity, $revision_id) : NULL;
if (!$revision || ($revision->wasDefaultRevision() && !$revision->isDefaultRevision())) {
$revision = NULL;
}
}
// Fall back to the latest revisions if no affected revision for the current
// content language could be found. This is acceptable as it means the
// entity is not translated. This is the correct logic also on monolingual
// sites.
if (!isset($revision)) {
$revision_id = $storage->getLatestRevisionId($entity->id());
$revision = $this->loadRevision($entity, $revision_id);
}
return $revision;
}
/**
* Loads the specified entity revision.
*
* @param \Drupal\Core\Entity\RevisionableInterface $entity
* The default revision of the entity being converted.
* @param string $revision_id
* The identifier of the revision to be loaded.
*
* @return \Drupal\Core\Entity\RevisionableInterface
* An entity revision object.
*/
protected function loadRevision(RevisionableInterface $entity, $revision_id) {
// We explicitly perform a loose equality check, since a revision ID may be
// returned as an integer or a string.
if ($entity->getLoadedRevisionId() != $revision_id) {
/** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */
$storage = $this->entityTypeManager->getStorage($entity->getEntityTypeId());
return $storage->loadRevision($revision_id);
}
return $entity;
}
}
......@@ -7,6 +7,8 @@
*/
interface EntityRepositoryInterface {
const CONTEXT_ID_LEGACY_CONTEXT_OPERATION = '@entity.repository:legacy_context_operation';
/**
* Loads an entity by UUID.
*
......@@ -69,4 +71,100 @@ public function loadEntityByConfigTarget($entity_type_id, $target);
*/
public function getTranslationFromContext(EntityInterface $entity, $langcode = NULL, $context = []);
/**
* Retrieves the active entity variant matching the specified context.
*
* If an entity type is revisionable and/or translatable, which entity variant
* should be handled depends on the context in which the manipulation happens.
* Based on the specified contextual information, revision and translation
* negotiation needs to be performed to return the active variant, that is the
* most up-to-date entity variant in the context scope. This may or may not be
* an entity variant intended for unprivileged user consumption, in fact it
* might be a work in progress containing yet to be published information. The
* active variant should always be retrieved when editing an entity, both in
* form and in REST workflows, or previewing the related changes.
*
* The negotiation process will not perform any access check, so it is the
* responsibility of the caller to verify that the user manipulating the
* entity variant is actually allowed to do so.
*
* @param string $entity_type_id
* The entity type identifier.
* @param int|string $entity_id
* An entity identifier.
* @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
* (optional) An associative array of objects representing the contexts the
* entity will be edited in keyed by fully qualified context ID. Defaults to
* the currently available contexts.
*
* @return \Drupal\Core\Entity\EntityInterface|null
* An entity object variant or NULL if the entity does not exist.
*/
public function getActive($entity_type_id, $entity_id, array $contexts = NULL);
/**
* Retrieves the active entity variants matching the specified context.
*
* @param string $entity_type_id
* The entity type identifier.
* @param int[]|string[] $entity_ids
* An array of entity identifiers.
* @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
* (optional) An associative array of objects representing the contexts the
* entity will be edited in keyed by fully qualified context ID. Defaults to
* the currently available contexts.
*
* @return \Drupal\Core\Entity\EntityInterface
* An array of entity object variants keyed by entity ID.
*
* @see getActive()
*/
public function getActiveMultiple($entity_type_id, array $entity_ids, array $contexts = NULL);
/**
* Retrieves the canonical entity variant matching the specified context.
*
* If an entity type is revisionable and/or translatable, which entity variant
* should be handled depends on the context in which the manipulation happens.
* This will return the fittest entity variant intended for unprivileged user
* consumption matching the specified context. This is typically the variant
* that would be displayed on the entity's canonical route.
*
* The negotiation process will not perform any access check, so it is the
* responsibility of the caller to verify that the user manipulating the
* entity variant is actually allowed to do so.
*
* @param string $entity_type_id
* The entity type identifier.
* @param int|string $entity_id
* An entity identifier.
* @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
* (optional) An associative array of objects representing the contexts the
* entity will be edited in keyed by fully qualified context ID. Defaults to
* the currently available contexts.
*
* @return \Drupal\Core\Entity\EntityInterface|null
* An entity object variant or NULL if the entity does not exist.
*/
public function getCanonical($entity_type_id, $entity_id, array $contexts = NULL);
/**
* Retrieves the canonical entity variants matching the specified context.
*
* @param string $entity_type_id
* The entity type identifier.
* @param int[]|string[] $entity_ids
* An array of entity identifiers.
* @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
* (optional) An associative array of objects representing the contexts the
* entity will be edited in keyed by fully qualified context ID. Defaults to
* the currently available contexts.
*
* @return \Drupal\Core\Entity\EntityInterface
* An array of entity object variants keyed by entity ID.
*
* @see getCanonical()
*/
public function getCanonicalMultiple($entity_type_id, array $entity_ids, array $contexts = NULL);
}
......@@ -2,13 +2,11 @@
namespace Drupal\Core\ParamConverter;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Routing\AdminContext;
use Symfony\Component\Routing\Route;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
/**
* Makes sure the unmodified ConfigEntity is loaded on admin pages.
......@@ -50,13 +48,11 @@ class AdminPathConfigEntityConverter extends EntityConverter {
* The config factory.
* @param \Drupal\Core\Routing\AdminContext $admin_context
* The route admin context service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, AdminContext $admin_context, LanguageManagerInterface $language_manager = NULL, EntityRepositoryInterface $entity_repository = NULL) {
parent::__construct($entity_type_manager, $language_manager, $entity_repository);
public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, AdminContext $admin_context, $entity_repository = NULL) {
parent::__construct($entity_type_manager, $entity_repository);
$this->configFactory = $config_factory;
$this->adminContext = $admin_context;
......
......@@ -3,14 +3,13 @@
namespace Drupal\Core\ParamConverter;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\RevisionableInterface;
use Drupal\Core\Entity\TranslatableRevisionableInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\TypedData\TranslatableInterface;
use Symfony\Component\Routing\Route;
......@@ -74,7 +73,10 @@ class EntityConverter implements ParamConverterInterface {
/**
* {@inheritdoc}
*/
protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
protected $deprecatedProperties = [
'entityManager' => 'entity.manager',
'languageManager' => 'language_manager',
];
/**
* Entity type manager which performs the upcasting in the end.
......@@ -90,36 +92,28 @@ class EntityConverter implements ParamConverterInterface {
*/
protected $entityRepository;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* Constructs a new EntityConverter.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Language\LanguageManagerInterface|null $language_manager
* (optional) The language manager. Defaults to none.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
*
* @see https://www.drupal.org/node/2549139
* @see https://www.drupal.org/node/2938929
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, LanguageManagerInterface $language_manager = NULL, EntityRepositoryInterface $entity_repository = NULL) {
public function __construct(EntityTypeManagerInterface $entity_type_manager, $entity_repository = NULL) {
if ($entity_type_manager instanceof EntityManagerInterface) {
@trigger_error('Passing the entity.manager service to EntityConverter::__construct() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Pass the entity_type.manager service instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
}
$this->entityTypeManager = $entity_type_manager;
if ($entity_repository) {
$this->entityRepository = $entity_repository;
}
else {
@trigger_error('The entity.repository service must be passed to EntityConverter::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$this->entityRepository = \Drupal::service('entity.repository');
if (!($entity_repository instanceof EntityRepositoryInterface)) {
@trigger_error('Calling EntityConverter::__construct() with the $entity_repository argument is supported in drupal:8.7.0 and will be required before drupal:9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$entity_repository = \Drupal::service('entity.repository');
}
$this->languageManager = $language_manager;
$this->entityRepository = $entity_repository;
}
/**
......@@ -127,32 +121,38 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Lan
*/
public function convert($value, $definition, $name, array $defaults) {
$entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults);
$storage = $this->entityTypeManager->getStorage($entity_type_id);
$entity_definition = $this->entityTypeManager->getDefinition($entity_type_id);
$entity = $storage->load($value);
// If the entity type is revisionable and the parameter has the
// "load_latest_revision" flag, load the latest revision.
if ($entity instanceof RevisionableInterface && !empty($definition['load_latest_revision']) && $entity_definition->isRevisionable()) {
// Retrieve the latest revision ID taking translations into account.
$langcode = $this->languageManager()
->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
->getId();
$entity = $this->getLatestTranslationAffectedRevision($entity, $langcode);
// "load_latest_revision" flag, load the active variant.
if (!empty($definition['load_latest_revision'])) {
return $this->entityRepository->getActive($entity_type_id, $value);
}
// If the entity type is translatable, ensure we return the proper
// translation object for the current context.
if ($entity instanceof EntityInterface && $entity instanceof TranslatableInterface) {
$entity = $this->entityRepository->getTranslationFromContext($entity, NULL, ['operation' => 'entity_upcast']);
// Do not inject the context repository as it is not an actual dependency:
// it will be removed once both the TODOs below are fixed.
/** @var \Drupal\Core\Plugin\Context\ContextRepositoryInterface $contexts_repository */
$contexts_repository = \Drupal::service('context.repository');
// @todo Consider deprecating the legacy context operation altogether in
// https://www.drupal.org/node/3031124.
$contexts = $contexts_repository->getAvailableContexts();
$contexts[EntityRepositoryInterface::CONTEXT_ID_LEGACY_CONTEXT_OPERATION] =
new Context(new ContextDefinition('string'), 'entity_upcast');
// @todo At the moment we do not need the current user context, which is
// triggering some test failures. We can remove these lines once
// https://www.drupal.org/node/2934192 is fixed.
$context_id = '@user.current_user_context:current_user';
if (isset($contexts[$context_id])) {
$account = $contexts[$context_id]->getContextValue();
unset($account->_skipProtectedUserFieldConstraint);
unset($contexts[$context_id]);
}
$entity = $this->entityRepository->getCanonical($entity_type_id, $value, $contexts);
return $entity;
}
/**
* Returns the ID of the latest revision translation of the specified entity.
* Returns the latest revision translation of the specified entity.
*
* @param \Drupal\Core\Entity\RevisionableInterface $entity
* The default revision of the entity being converted.
......@@ -163,39 +163,25 @@ public function convert($value, $definition, $name, array $defaults) {
* The latest translation-affecting revision for the specified entity, or
* just the latest revision, if the specified entity is not translatable or
* does not have a matching translation yet.
*
* @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0.
* Use \Drupal\Core\Entity\EntityRepositoryInterface::getActive() instead.
*/
protected function getLatestTranslationAffectedRevision(RevisionableInterface $entity, $langcode) {
$revision = NULL;
$storage = $this->entityTypeManager->getStorage($entity->getEntityTypeId());
if ($entity instanceof TranslatableRevisionableInterface && $entity->isTranslatable()) {
/** @var \Drupal\Core\Entity\TranslatableRevisionableStorageInterface $storage */
$revision_id = $storage->getLatestTranslationAffectedRevisionId($entity->id(), $langcode);