Issue #3028671 by Berdir: Add @trigger_error() to deprecated and already (almost) unused EntityManager methods
parent
3f2ab9daa7
commit
f49d8f156a
|
@ -108,10 +108,6 @@ interface EntityFieldManagerInterface {
|
|||
*
|
||||
* @param bool $use_caches
|
||||
* FALSE to not use any caches.
|
||||
*
|
||||
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
|
||||
*
|
||||
* @todo Remove in https://www.drupal.org/node/2549143.
|
||||
*/
|
||||
public function useCaches($use_caches = FALSE);
|
||||
|
||||
|
|
|
@ -362,6 +362,7 @@ class EntityManager implements EntityManagerInterface, ContainerAwareInterface {
|
|||
* @see https://www.drupal.org/node/2549139
|
||||
*/
|
||||
public function getEntityTypeLabels($group = FALSE) {
|
||||
@trigger_error('EntityManagerInterface::getEntityTypeLabels() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityTypeRepositoryInterface::getEntityTypeLabels() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
|
||||
return $this->container->get('entity_type.repository')->getEntityTypeLabels($group);
|
||||
}
|
||||
|
||||
|
@ -534,6 +535,7 @@ class EntityManager implements EntityManagerInterface, ContainerAwareInterface {
|
|||
* @see https://www.drupal.org/node/2549139
|
||||
*/
|
||||
public function getEntityTypeFromClass($class_name) {
|
||||
@trigger_error('EntityManagerInterface::getEntityTypeFromClass() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityTypeRepositoryInterface::getEntityTypeFromClass() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
|
||||
return $this->container->get('entity_type.repository')->getEntityTypeFromClass($class_name);
|
||||
}
|
||||
|
||||
|
@ -666,13 +668,22 @@ class EntityManager implements EntityManagerInterface, ContainerAwareInterface {
|
|||
* @see https://www.drupal.org/node/2549139
|
||||
*/
|
||||
public function getLastInstalledDefinition($entity_type_id) {
|
||||
@trigger_error('EntityManagerInterface::getLastInstalledDefinition() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface::getLastInstalledDefinition() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
|
||||
return $this->container->get('entity.last_installed_schema.repository')->getLastInstalledDefinition($entity_type_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated EntityManagerInterface::useCaches() is deprecated in 8.0.0 and
|
||||
* will be removed before Drupal 9.0.0. Use
|
||||
* \Drupal\Core\Entity\EntityTypeManagerInterface::useCaches() and/or
|
||||
* Drupal\Core\Entity\EntityFieldManagerInterface::useCaches() instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2549139
|
||||
*/
|
||||
public function useCaches($use_caches = FALSE) {
|
||||
@trigger_error('EntityManagerInterface::useCaches() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityTypeManagerInterface::useCaches() and/or Drupal\Core\Entity\EntityFieldManagerInterface::useCaches() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
|
||||
$this->container->get('entity_type.manager')->useCaches($use_caches);
|
||||
|
||||
// @todo EntityFieldManager is not a plugin manager, and should not co-opt
|
||||
|
@ -690,6 +701,7 @@ class EntityManager implements EntityManagerInterface, ContainerAwareInterface {
|
|||
* @see https://www.drupal.org/node/2549139
|
||||
*/
|
||||
public function getLastInstalledFieldStorageDefinitions($entity_type_id) {
|
||||
@trigger_error('EntityManagerInterface::getLastInstalledFieldStorageDefinitions() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface::getLastInstalledFieldStorageDefinitions() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
|
||||
return $this->container->get('entity.last_installed_schema.repository')->getLastInstalledFieldStorageDefinitions($entity_type_id);
|
||||
}
|
||||
|
||||
|
@ -729,6 +741,7 @@ class EntityManager implements EntityManagerInterface, ContainerAwareInterface {
|
|||
* @see https://www.drupal.org/node/2549139
|
||||
*/
|
||||
public function createInstance($plugin_id, array $configuration = []) {
|
||||
@trigger_error('EntityManagerInterface::createInstance() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityTypeManagerInterface::createInstance() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
|
||||
return $this->container->get('entity_type.manager')->createInstance($plugin_id, $configuration);
|
||||
}
|
||||
|
||||
|
@ -742,6 +755,7 @@ class EntityManager implements EntityManagerInterface, ContainerAwareInterface {
|
|||
* @see https://www.drupal.org/node/2549139
|
||||
*/
|
||||
public function getInstance(array $options) {
|
||||
@trigger_error('EntityManagerInterface::getInstance() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityTypeManagerInterface::getInstance() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
|
||||
return $this->container->get('entity_type.manager')->getInstance($options);
|
||||
}
|
||||
|
||||
|
|
|
@ -357,7 +357,7 @@ class EntityReferenceItem extends FieldItemBase implements OptionsProviderInterf
|
|||
$element['target_type'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => t('Type of item to reference'),
|
||||
'#options' => \Drupal::entityManager()->getEntityTypeLabels(TRUE),
|
||||
'#options' => \Drupal::service('entity_type.repository')->getEntityTypeLabels(TRUE),
|
||||
'#default_value' => $this->getSetting('target_type'),
|
||||
'#required' => TRUE,
|
||||
'#disabled' => $has_data,
|
||||
|
|
|
@ -223,7 +223,7 @@ function content_translation_entity_base_field_info(EntityTypeInterface $entity_
|
|||
$entity_type_id = $entity_type->id();
|
||||
if ($manager->isSupported($entity_type_id)) {
|
||||
$definitions = $manager->getTranslationHandler($entity_type_id)->getFieldDefinitions();
|
||||
$installed_storage_definitions = \Drupal::entityManager()->getLastInstalledFieldStorageDefinitions($entity_type_id);
|
||||
$installed_storage_definitions = \Drupal::service('entity.last_installed_schema.repository')->getLastInstalledFieldStorageDefinitions($entity_type_id);
|
||||
// We return metadata storage fields whenever content translation is enabled
|
||||
// or it was enabled before, so that we keep translation metadata around
|
||||
// when translation is disabled.
|
||||
|
|
|
@ -9,8 +9,9 @@ use Drupal\Core\Entity\EntityChangedInterface;
|
|||
use Drupal\Core\Entity\EntityChangesDetectionTrait;
|
||||
use Drupal\Core\Entity\EntityHandlerInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
|
@ -107,8 +108,8 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface, E
|
|||
* The language manager.
|
||||
* @param \Drupal\content_translation\ContentTranslationManagerInterface $manager
|
||||
* The content translation manager service.
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\Session\AccountInterface $current_user
|
||||
* The current user.
|
||||
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
|
||||
|
@ -116,14 +117,18 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface, E
|
|||
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
|
||||
* The date formatter service.
|
||||
*/
|
||||
public function __construct(EntityTypeInterface $entity_type, LanguageManagerInterface $language_manager, ContentTranslationManagerInterface $manager, EntityManagerInterface $entity_manager, AccountInterface $current_user, MessengerInterface $messenger, DateFormatterInterface $date_formatter) {
|
||||
public function __construct(EntityTypeInterface $entity_type, LanguageManagerInterface $language_manager, ContentTranslationManagerInterface $manager, EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user, MessengerInterface $messenger, DateFormatterInterface $date_formatter, EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository = NULL) {
|
||||
$this->entityTypeId = $entity_type->id();
|
||||
$this->entityType = $entity_type;
|
||||
$this->languageManager = $language_manager;
|
||||
$this->manager = $manager;
|
||||
$this->entityTypeManager = $entity_manager;
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->currentUser = $current_user;
|
||||
$this->fieldStorageDefinitions = $entity_manager->getLastInstalledFieldStorageDefinitions($this->entityTypeId);
|
||||
if (!$entity_last_installed_schema_repository) {
|
||||
@trigger_error('Calling ContentTranslationHandler::__construct() with the $entity_last_installed_schema_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_last_installed_schema_repository = \Drupal::service('entity.last_installed_schema.repository');
|
||||
}
|
||||
$this->fieldStorageDefinitions = $entity_last_installed_schema_repository->getLastInstalledFieldStorageDefinitions($this->entityTypeId);
|
||||
$this->messenger = $messenger;
|
||||
$this->dateFormatter = $date_formatter;
|
||||
}
|
||||
|
@ -136,10 +141,11 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface, E
|
|||
$entity_type,
|
||||
$container->get('language_manager'),
|
||||
$container->get('content_translation.manager'),
|
||||
$container->get('entity.manager'),
|
||||
$container->get('entity_type.manager'),
|
||||
$container->get('current_user'),
|
||||
$container->get('messenger'),
|
||||
$container->get('date.formatter')
|
||||
$container->get('date.formatter'),
|
||||
$container->get('entity.last_installed_schema.repository')
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,13 +20,6 @@ class UpdateApiEntityDefinitionUpdateTest extends BrowserTestBase {
|
|||
*/
|
||||
protected static $modules = ['entity_test'];
|
||||
|
||||
/**
|
||||
* The entity manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The entity definition update manager.
|
||||
*
|
||||
|
@ -40,7 +33,6 @@ class UpdateApiEntityDefinitionUpdateTest extends BrowserTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->entityManager = $this->container->get('entity.manager');
|
||||
$this->updatesManager = $this->container->get('entity.definition_update_manager');
|
||||
|
||||
$admin = $this->drupalCreateUser([], FALSE, TRUE);
|
||||
|
@ -181,8 +173,8 @@ class UpdateApiEntityDefinitionUpdateTest extends BrowserTestBase {
|
|||
* The reloaded entity object.
|
||||
*/
|
||||
protected function reloadEntity(EntityTest $entity) {
|
||||
$this->entityManager->useCaches(FALSE);
|
||||
$this->entityManager->getStorage('entity_test')->resetCache([$entity->id()]);
|
||||
\Drupal::entityTypeManager()->useCaches(FALSE);
|
||||
\Drupal::service('entity_field.manager')->useCaches(FALSE);
|
||||
return EntityTest::load($entity->id());
|
||||
}
|
||||
|
||||
|
|
|
@ -411,7 +411,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
|
|||
|
||||
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
|
||||
$table_mapping = $storage->getTableMapping();
|
||||
$storage_definition = $this->entityManager->getLastInstalledFieldStorageDefinitions($entity_type_id)['new_base_field'];
|
||||
$storage_definition = \Drupal::service('entity.last_installed_schema.repository')->getLastInstalledFieldStorageDefinitions($entity_type_id)['new_base_field'];
|
||||
|
||||
// Save an entity with the base field populated.
|
||||
$entity = $storage->create(['new_base_field' => 'foo']);
|
||||
|
@ -574,7 +574,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
|
|||
|
||||
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
|
||||
$table_mapping = $storage->getTableMapping();
|
||||
$storage_definition = $this->entityManager->getLastInstalledFieldStorageDefinitions('entity_test_update')['new_bundle_field'];
|
||||
$storage_definition = \Drupal::service('entity.last_installed_schema.repository')->getLastInstalledFieldStorageDefinitions('entity_test_update')['new_bundle_field'];
|
||||
|
||||
// Check that the bundle field has a dedicated table.
|
||||
$dedicated_table_name = $table_mapping->getDedicatedDataTableName($storage_definition);
|
||||
|
|
|
@ -6,7 +6,9 @@ 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\EntityType;
|
||||
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeRepositoryInterface;
|
||||
|
@ -61,6 +63,13 @@ class EntityManagerTest extends UnitTestCase {
|
|||
*/
|
||||
protected $entityRepository;
|
||||
|
||||
/**
|
||||
* The entity last installed schema repository.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepository|\Prophecy\Prophecy\ProphecyInterface
|
||||
*/
|
||||
protected $entityLastInstalledSchemaRepository;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -72,6 +81,7 @@ class EntityManagerTest extends UnitTestCase {
|
|||
$this->entityTypeBundleInfo = $this->prophesize(EntityTypeBundleInfoInterface::class);
|
||||
$this->entityFieldManager = $this->prophesize(EntityFieldManagerInterface::class);
|
||||
$this->entityRepository = $this->prophesize(EntityRepositoryInterface::class);
|
||||
$this->entityLastInstalledSchemaRepository = $this->prophesize(EntityLastInstalledSchemaRepositoryInterface::class);
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('entity_type.manager', $this->entityTypeManager->reveal());
|
||||
|
@ -79,6 +89,7 @@ class EntityManagerTest extends UnitTestCase {
|
|||
$container->set('entity_type.bundle.info', $this->entityTypeBundleInfo->reveal());
|
||||
$container->set('entity_field.manager', $this->entityFieldManager->reveal());
|
||||
$container->set('entity.repository', $this->entityRepository->reveal());
|
||||
$container->set('entity.last_installed_schema.repository', $this->entityLastInstalledSchemaRepository->reveal());
|
||||
|
||||
$this->entityManager = new EntityManager();
|
||||
$this->entityManager->setContainer($container);
|
||||
|
@ -180,4 +191,87 @@ class EntityManagerTest extends UnitTestCase {
|
|||
$this->assertInstanceOf(EntityInterface::class, $this->entityManager->loadEntityByConfigTarget('config_test', 'test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the getEntityTypeFromClass() method.
|
||||
*
|
||||
* @covers ::getEntityTypeFromClass
|
||||
*
|
||||
* @expectedDeprecation EntityManagerInterface::getEntityTypeFromClass() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityTypeRepositoryInterface::getEntityTypeFromClass() instead. See https://www.drupal.org/node/2549139.
|
||||
*/
|
||||
public function testGetEntityTypeFromClass() {
|
||||
$class = '\Drupal\example\Entity\ExampleEntity';
|
||||
$this->entityTypeRepository->getEntityTypeFromClass($class)->shouldBeCalled()->willReturn('example_entity_type');
|
||||
|
||||
$this->assertEquals('example_entity_type', $this->entityManager->getEntityTypeFromClass($class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the getLastInstalledDefinition() method.
|
||||
*
|
||||
* @covers ::getLastInstalledDefinition
|
||||
*
|
||||
* @expectedDeprecation EntityManagerInterface::getLastInstalledDefinition() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface::getLastInstalledDefinition() instead. See https://www.drupal.org/node/2549139.
|
||||
*/
|
||||
public function testGetLastInstalledDefinition() {
|
||||
$entity_type_id = 'example_entity_type';
|
||||
$entity_type = new EntityType(['id' => $entity_type_id]);
|
||||
$this->entityLastInstalledSchemaRepository->getLastInstalledDefinition($entity_type_id)->shouldBeCalled()->willReturn($entity_type);
|
||||
|
||||
$this->assertEquals($entity_type, $this->entityManager->getLastInstalledDefinition($entity_type_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the getLastInstalledFieldStorageDefinitions() method.
|
||||
*
|
||||
* @covers ::getLastInstalledFieldStorageDefinitions
|
||||
*
|
||||
* @expectedDeprecation EntityManagerInterface::getLastInstalledFieldStorageDefinitions() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface::getLastInstalledFieldStorageDefinitions() instead. See https://www.drupal.org/node/2549139.
|
||||
*/
|
||||
public function testGetLastInstalledFieldStorageDefinitions() {
|
||||
$entity_type_id = 'example_entity_type';
|
||||
$this->entityLastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions($entity_type_id)->shouldBeCalled()->willReturn([]);
|
||||
|
||||
$this->assertEquals([], $this->entityManager->getLastInstalledFieldStorageDefinitions($entity_type_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the useCaches() method.
|
||||
*
|
||||
* @covers ::useCaches
|
||||
*
|
||||
* @expectedDeprecation EntityManagerInterface::useCaches() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityTypeManagerInterface::useCaches() and/or Drupal\Core\Entity\EntityFieldManagerInterface::useCaches() instead. See https://www.drupal.org/node/2549139.
|
||||
*/
|
||||
public function testUseCaches() {
|
||||
$this->entityTypeManager->useCaches(TRUE)->shouldBeCalled();
|
||||
$this->entityFieldManager->useCaches(TRUE)->shouldBeCalled();
|
||||
|
||||
$this->entityManager->useCaches(TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the createInstance() method.
|
||||
*
|
||||
* @covers ::createInstance
|
||||
*
|
||||
* @expectedDeprecation EntityManagerInterface::createInstance() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityTypeManagerInterface::createInstance() instead. See https://www.drupal.org/node/2549139.
|
||||
*/
|
||||
public function testCreateInstance() {
|
||||
$this->entityTypeManager->createInstance('plugin_id', ['example' => TRUE])->shouldBeCalled();
|
||||
|
||||
$this->entityManager->createInstance('plugin_id', ['example' => TRUE]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the getInstance() method.
|
||||
*
|
||||
* @covers ::getInstance
|
||||
*
|
||||
* @expectedDeprecation EntityManagerInterface::getInstance() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityTypeManagerInterface::getInstance() instead. See https://www.drupal.org/node/2549139.
|
||||
*/
|
||||
public function testGetInstance() {
|
||||
$this->entityTypeManager->getInstance(['example' => TRUE])->shouldBeCalled();
|
||||
|
||||
$this->entityManager->getInstance(['example' => TRUE]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue