Unverified Commit 094890e6 authored by larowlan's avatar larowlan

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;
......
......@@ -234,7 +234,7 @@ function entity_test_entity_bundle_info_alter(&$bundles) {
$state = \Drupal::state();
foreach ($bundles as $entity_type_id => &$all_bundle_info) {
if ($entity_info[$entity_type_id]->getProvider() == 'entity_test') {
if ($state->get('entity_test.translation')) {
if ($state->get('entity_test.translation') && $entity_info[$entity_type_id]->isTranslatable()) {
foreach ($all_bundle_info as $bundle_name => &$bundle_info) {
$bundle_info['translatable'] = TRUE;
if ($state->get('entity_test.untranslatable_fields.default_translation_affected')) {
......
......@@ -3,15 +3,13 @@
namespace Drupal\views_ui\ParamConverter;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\ParamConverter\AdminPathConfigEntityConverter;
use Drupal\Core\Routing\AdminContext;
use Symfony\Component\Routing\Route;
use Drupal\Core\ParamConverter\ParamConverterInterface;
use Drupal\Core\Routing\AdminContext;
use Drupal\Core\TempStore\SharedTempStoreFactory;
use Drupal\views_ui\ViewUI;
use Symfony\Component\Routing\Route;
/**
* Provides upcasting for a view entity to be used in the Views UI.
......@@ -49,12 +47,10 @@ class ViewUIConverter extends AdminPathConfigEntityConverter implements ParamCon
* 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, SharedTempStoreFactory $temp_store_factory, ConfigFactoryInterface $config_factory = NULL, AdminContext $admin_context = NULL, LanguageManagerInterface $language_manager = NULL, EntityRepositoryInterface $entity_repository = NULL) {
public function __construct(EntityTypeManagerInterface $entity_type_manager, SharedTempStoreFactory $temp_store_factory, ConfigFactoryInterface $config_factory = NULL, AdminContext $admin_context = NULL, $entity_repository = NULL) {
// The config factory and admin context are new arguments due to changing
// the parent. Avoid an error on updated sites by falling back to getting
// them from the container.
......@@ -65,7 +61,7 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Sha
if (!$admin_context) {
$admin_context = \Drupal::service('router.admin_context');
}
parent::__construct($entity_type_manager, $config_factory, $admin_context, $language_manager, $entity_repository);
parent::__construct($entity_type_manager, $config_factory, $admin_context, $entity_repository);
$this->tempStoreFactory = $temp_store_factory;
}
......
services:
paramconverter.views_ui:
class: Drupal\views_ui\ParamConverter\ViewUIConverter
arguments: ['@entity_type.manager', '@tempstore.shared', '@config.factory', '@router.admin_context', '@language_manager', '@entity.repository']
arguments: ['@entity_type.manager', '@tempstore.shared', '@config.factory', '@router.admin_context', '@entity.repository']
tags:
- { name: paramconverter, priority: 10 }
lazy: true
......@@ -3,11 +3,11 @@
namespace Drupal\Tests\Core\Entity;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityType;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
......@@ -57,7 +57,7 @@ class EntityManagerTest extends UnitTestCase {
protected $entityFieldManager;
/**
* The entity display repository.
* The entity repository.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface|\Prophecy\Prophecy\ProphecyInterface
*/
......@@ -274,4 +274,64 @@ public function testGetInstance() {
$this->entityManager->getInstance(['example' => TRUE]);
}
/**
* Tests the getActive() method.
*
* @covers ::getActive
*
* @expectedDeprecation 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.
*/
public function testGetActive() {
$entity_type_id = 'entity_test';
$entity_id = 0;
$contexts = [];
$this->entityRepository->getActive($entity_type_id, $entity_id, $contexts)->shouldBeCalled($entity_type_id, $entity_id, $contexts);
$this->entityManager->getActive($entity_type_id, $entity_id, $contexts);
}
/**
* Tests the getActiveMultiple() method.
*
* @covers ::getActiveMultiple
*
* @expectedDeprecation 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.
*/
public function testActiveMultiple() {
$entity_type_id = 'entity_test';
$entity_ids = [0];
$contexts = [];
$this->entityRepository->getActiveMultiple($entity_type_id, $entity_ids, $contexts)->shouldBeCalled($entity_type_id, $entity_ids, $contexts);
$this->entityManager->getActiveMultiple($entity_type_id, $entity_ids, $contexts);
}
/**
* Tests the getCanonical() method.
*
* @covers ::getCanonical
*
* @expectedDeprecation 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.
*/
public function testGetCanonical() {
$entity_type_id = 'entity_test';
$entity_id = '';
$contexts = [];
$this->entityRepository->getCanonical($entity_type_id, $entity_id, $contexts)->shouldBeCalled($entity_type_id, $entity_id, $contexts);
$this->entityManager->getCanonical($entity_type_id, $entity_id, $contexts);
}
/**
* Tests the getCanonicalMultiple() method.
*
* @covers ::getCanonicalMultiple
*
* @expectedDeprecation 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.
*/
public function testGetCanonicalMultiple() {
$entity_type_id = 'entity_test';
$entity_ids = [0];
$contexts = [];
$this->entityRepository->getCanonicalMultiple($entity_type_id, $entity_ids, $contexts)->shouldBeCalled($entity_type_id, $entity_ids, $contexts);
$this->entityManager->getCanonicalMultiple($entity_type_id, $entity_ids, $contexts);
}
}
......@@ -8,6 +8,7 @@
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Plugin\Context\ContextRepositoryInterface;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;
......@@ -31,6 +32,13 @@ class EntityRepositoryTest extends UnitTestCase {
*/
protected $languageManager;
/**
* The context repository.
*
* @var \Drupal\Core\Plugin\Context\ContextRepositoryInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $contextRepository;
/**
* The entity repository under test.
*
......@@ -46,8 +54,9 @@ protected function setUp() {
$this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
$this->languageManager = $this->prophesize(LanguageManagerInterface::class);
$this->contextRepository = $this->prophesize(ContextRepositoryInterface::class);
$this->entityRepository = new EntityRepository($this->entityTypeManager->reveal(), $this->languageManager->reveal());
$this->entityRepository = new EntityRepository($this->entityTypeManager->reveal(), $this->languageManager->reveal(), $this->contextRepository->reveal());
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment