Commit 81915a93 authored by alexpott's avatar alexpott

Issue #3025427 by Berdir, amateescu: Add @trigger_error() to deprecated...

Issue #3025427 by Berdir, amateescu: Add @trigger_error() to deprecated EntityManager->EntityTypeBundleInfo methods
parent 4b68814a
......@@ -5,6 +5,7 @@
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
......@@ -15,6 +16,12 @@
* Base class for content entity storage handlers.
*/
abstract class ContentEntityStorageBase extends EntityStorageBase implements ContentEntityStorageInterface, DynamicallyFieldableEntityStorageInterface {
use DeprecatedServicePropertyTrait;
/**
* {@inheritdoc}
*/
protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
/**
* The entity bundle key.
......@@ -24,11 +31,18 @@ abstract class ContentEntityStorageBase extends EntityStorageBase implements Con
protected $bundleKey = FALSE;
/**
* The entity manager.
* The entity field manager service.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityManager;
protected $entityFieldManager;
/**
* The entity bundle info.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* Cache backend.
......@@ -49,18 +63,25 @@ abstract class ContentEntityStorageBase extends EntityStorageBase implements Con
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* The cache backend to be used.
* @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface|null $memory_cache
* The memory cache backend.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle info.
*/
public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, MemoryCacheInterface $memory_cache = NULL) {
public function __construct(EntityTypeInterface $entity_type, EntityFieldManagerInterface $entity_field_manager, CacheBackendInterface $cache, MemoryCacheInterface $memory_cache = NULL, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL) {
parent::__construct($entity_type, $memory_cache);
$this->bundleKey = $this->entityType->getKey('bundle');
$this->entityManager = $entity_manager;
$this->entityFieldManager = $entity_field_manager;
$this->cacheBackend = $cache;
if (!$entity_type_bundle_info) {
@trigger_error('Calling ContentEntityStorageBase::__construct() with the $entity_type_bundle_info 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_type_bundle_info = \Drupal::service('entity_type.bundle.info');
}
$this->entityTypeBundleInfo = $entity_type_bundle_info;
}
/**
......@@ -69,9 +90,10 @@ public function __construct(EntityTypeInterface $entity_type, EntityManagerInter
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
$entity_type,
$container->get('entity.manager'),
$container->get('entity_field.manager'),
$container->get('cache.entity'),
$container->get('entity.memory_cache')
$container->get('entity.memory_cache'),
$container->get('entity_type.bundle.info')
);
}
......@@ -124,7 +146,7 @@ public function createWithSampleValues($bundle = FALSE, array $values = []) {
if (!$bundle) {
throw new EntityStorageException("No entity bundle was specified");
}
if (!array_key_exists($bundle, $this->entityManager->getBundleInfo($this->entityTypeId))) {
if (!array_key_exists($bundle, $this->entityTypeBundleInfo->getBundleInfo($this->entityTypeId))) {
throw new EntityStorageException(sprintf("Missing entity bundle. The \"%s\" bundle does not exist", $bundle));
}
$values[$bundle_key] = $bundle;
......@@ -963,7 +985,7 @@ protected function populateAffectedRevisionTranslations(ContentEntityInterface $
* The sanitized list of entity key values.
*/
protected function cleanIds(array $ids, $entity_key = 'id') {
$definitions = $this->entityManager->getBaseFieldDefinitions($this->entityTypeId);
$definitions = $this->entityFieldManager->getBaseFieldDefinitions($this->entityTypeId);
$field_name = $this->entityType->getKey($entity_key);
if ($field_name && $definitions[$field_name]->getType() == 'integer') {
$ids = array_filter($ids, function ($id) {
......
......@@ -306,39 +306,42 @@ public function clearCachedFieldDefinitions() {
/**
* {@inheritdoc}
*
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
* @deprecated in drupal:8.0.0, will be removed before drupal:9.0.0.
* Use \Drupal\Core\Entity\EntityTypeBundleInfoInterface::clearCachedBundles()
* instead.
*
* @see https://www.drupal.org/node/2549139
*/
public function clearCachedBundles() {
@trigger_error('EntityManagerInterface::clearCachedBundles() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityTypeBundleInfoInterface::clearCachedBundles() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$this->container->get('entity_type.bundle.info')->clearCachedBundles();
}
/**
* {@inheritdoc}
*
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
* @deprecated in drupal:8.0.0, will be removed before drupal:9.0.0.
* Use \Drupal\Core\Entity\EntityTypeBundleInfoInterface::getBundleInfo()
* instead.
*
* @see https://www.drupal.org/node/2549139
*/
public function getBundleInfo($entity_type_id) {
@trigger_error('EntityManagerInterface::getBundleInfo() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityTypeBundleInfoInterface::getBundleInfo() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
return $this->container->get('entity_type.bundle.info')->getBundleInfo($entity_type_id);
}
/**
* {@inheritdoc}
*
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
* @deprecated in drupal:8.0.0, will be removed before drupal:9.0.0.
* Use \Drupal\Core\Entity\EntityTypeBundleInfoInterface::getAllBundleInfo()
* instead.
*
* @see https://www.drupal.org/node/2549139
*/
public function getAllBundleInfo() {
@trigger_error('EntityManagerInterface::getAllBundleInfo() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityTypeBundleInfoInterface::getAllBundleInfo() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
return $this->container->get('entity_type.bundle.info')->getAllBundleInfo();
}
......
......@@ -5,8 +5,11 @@
use Drupal\Core\Database\Connection;
use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\EntityTypeInterface;
......@@ -28,16 +31,29 @@
class SqlContentEntityStorageSchema implements DynamicallyFieldableEntityStorageSchemaInterface {
use DependencySerializationTrait;
use DeprecatedServicePropertyTrait;
use SqlFieldableEntityTypeListenerTrait {
onFieldableEntityTypeUpdate as traitOnFieldableEntityTypeUpdate;
}
/**
* The entity manager.
* {@inheritdoc}
*/
protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The entity last installed schema repository.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface
*/
protected $entityManager;
protected $entityLastInstalledSchemaRepository;
/**
* The entity type this schema builder is responsible for.
......@@ -99,21 +115,34 @@ class SqlContentEntityStorageSchema implements DynamicallyFieldableEntityStorage
/**
* Constructs a SqlContentEntityStorageSchema.
*
* @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\Entity\ContentEntityTypeInterface $entity_type
* The entity type.
* @param \Drupal\Core\Entity\Sql\SqlContentEntityStorage $storage
* The storage of the entity type. This must be an SQL-based storage.
* @param \Drupal\Core\Database\Connection $database
* The database connection to be used.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
* @param \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository
* The entity last installed schema repository.
*/
public function __construct(EntityManagerInterface $entity_manager, ContentEntityTypeInterface $entity_type, SqlContentEntityStorage $storage, Connection $database) {
$this->entityManager = $entity_manager;
public function __construct(EntityTypeManagerInterface $entity_type_manager, ContentEntityTypeInterface $entity_type, SqlContentEntityStorage $storage, Connection $database, EntityFieldManagerInterface $entity_field_manager = NULL, EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository = NULL) {
$this->entityTypeManager = $entity_type_manager;
$this->entityType = $entity_type;
$this->fieldStorageDefinitions = $entity_manager->getFieldStorageDefinitions($entity_type->id());
if (!$entity_field_manager) {
@trigger_error('Calling SqlContentEntityStorageSchema::__construct() with the $entity_field_manager 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_field_manager = \Drupal::service('entity_field.manager');
}
$this->fieldStorageDefinitions = $entity_field_manager->getFieldStorageDefinitions($entity_type->id());
$this->storage = $storage;
$this->database = $database;
if (!$entity_last_installed_schema_repository) {
@trigger_error('Calling SqlContentEntityStorageSchema::__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->entityLastInstalledSchemaRepository = $entity_last_installed_schema_repository;
}
/**
......@@ -290,7 +319,7 @@ public function requiresEntityDataMigration(EntityTypeInterface $entity_type, En
}
// Use the original entity type since the storage has not been updated.
$original_storage = $this->entityManager->createHandlerInstance($original_storage_class, $original);
$original_storage = $this->entityTypeManager->createHandlerInstance($original_storage_class, $original);
return $original_storage->hasData();
}
......@@ -392,7 +421,7 @@ public function onEntityTypeDelete(EntityTypeInterface $entity_type) {
$this->checkEntityType($entity_type);
$schema_handler = $this->database->schema();
$field_storage_definitions = $this->entityManager->getLastInstalledFieldStorageDefinitions($entity_type->id());
$field_storage_definitions = $this->entityLastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions($entity_type->id());
$table_mapping = $this->storage->getCustomTableMapping($entity_type, $field_storage_definitions);
// Delete entity and field tables.
......@@ -631,7 +660,7 @@ public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $
}
// Retrieve a table mapping which contains the deleted field still.
$storage_definitions = $this->entityManager->getLastInstalledFieldStorageDefinitions($this->entityType->id());
$storage_definitions = $this->entityLastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions($this->entityType->id());
$table_mapping = $this->storage->getTableMapping($storage_definitions);
$field_table_name = $table_mapping->getFieldTableName($storage_definition->getName());
......@@ -1603,7 +1632,7 @@ protected function deleteSharedTableSchema(FieldStorageDefinitionInterface $stor
$deleted_field_name = $storage_definition->getName();
$table_mapping = $this->storage->getTableMapping(
$this->entityManager->getLastInstalledFieldStorageDefinitions($this->entityType->id())
$this->entityLastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions($this->entityType->id())
);
$column_names = $table_mapping->getColumnNames($deleted_field_name);
$schema_handler = $this->database->schema();
......@@ -2011,7 +2040,7 @@ protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $st
// must use the last installed version of that, as the new field might
// be created in an update function and the storage definition of the
// "from" field might get changed later.
$last_installed_storage_definitions = $this->entityManager->getLastInstalledFieldStorageDefinitions($this->entityType->id());
$last_installed_storage_definitions = $this->entityLastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions($this->entityType->id());
if (!isset($last_installed_storage_definitions[$initial_value_field_name])) {
throw new FieldException("Illegal initial value definition on {$storage_definition->getName()}: The field $initial_value_field_name does not exist.");
}
......
......@@ -20,7 +20,7 @@ trait SqlFieldableEntityTypeListenerTrait {
*/
public function onFieldableEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $field_storage_definitions, array $original_field_storage_definitions, array &$sandbox = NULL) {
/** @var \Drupal\Core\Entity\EntityStorageInterface $original_storage */
$original_storage = $this->entityManager->createHandlerInstance($original->getStorageClass(), $original);
$original_storage = $this->entityTypeManager->createHandlerInstance($original->getStorageClass(), $original);
$has_data = $original_storage->hasData();
// If 'progress' is not set, then this will be the first run of the batch.
......@@ -59,7 +59,7 @@ public function onFieldableEntityTypeUpdate(EntityTypeInterface $entity_type, En
}
$sandbox['original_storage'] = $original_storage;
$sandbox['temporary_storage'] = $this->entityManager->createHandlerInstance($entity_type->getStorageClass(), $entity_type);
$sandbox['temporary_storage'] = $this->entityTypeManager->createHandlerInstance($entity_type->getStorageClass(), $entity_type);
$this->preUpdateEntityTypeSchema($entity_type, $original, $field_storage_definitions, $original_field_storage_definitions, $sandbox);
}
......
......@@ -391,9 +391,10 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
// provided by the module that is being uninstalled.
// @todo Clean this up in https://www.drupal.org/node/2350111.
$entity_manager = \Drupal::entityManager();
$entity_type_bundle_info = \Drupal::service('entity_type.bundle.info');
foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type->getProvider() == $module) {
foreach (array_keys($entity_manager->getBundleInfo($entity_type_id)) as $bundle) {
foreach (array_keys($entity_type_bundle_info->getBundleInfo($entity_type_id)) as $bundle) {
\Drupal::service('entity_bundle.listener')->onBundleDelete($bundle, $entity_type_id);
}
}
......
......@@ -603,7 +603,7 @@ public function getSettableOptions(AccountInterface $account = NULL) {
// Rebuild the array by changing the bundle key into the bundle label.
$target_type = $field_definition->getSetting('target_type');
$bundles = \Drupal::entityManager()->getBundleInfo($target_type);
$bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo($target_type);
$return = [];
foreach ($options as $bundle => $entity_ids) {
......
......@@ -5,9 +5,12 @@
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\Core\Session\AccountInterface;
......@@ -36,8 +39,8 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
* An array of entity info for the entity type.
* @param \Drupal\Core\Database\Connection $database
* The database connection to be used.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
......@@ -45,10 +48,16 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache
* The memory cache.
* The memory cache.*
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle info.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository
* The entity last installed schema repository.
*/
public function __construct(EntityTypeInterface $entity_info, Connection $database, EntityManagerInterface $entity_manager, AccountInterface $current_user, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache) {
parent::__construct($entity_info, $database, $entity_manager, $cache, $language_manager, $memory_cache);
public function __construct(EntityTypeInterface $entity_info, Connection $database, EntityFieldManagerInterface $entity_field_manager, AccountInterface $current_user, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, EntityTypeManagerInterface $entity_type_manager = NULL, EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository = NULL) {
parent::__construct($entity_info, $database, $entity_field_manager, $cache, $language_manager, $memory_cache, $entity_type_bundle_info, $entity_type_manager, $entity_last_installed_schema_repository);
$this->currentUser = $current_user;
}
......@@ -59,11 +68,14 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
return new static(
$entity_info,
$container->get('database'),
$container->get('entity.manager'),
$container->get('entity_field.manager'),
$container->get('current_user'),
$container->get('cache.entity'),
$container->get('language_manager'),
$container->get('entity.memory_cache')
$container->get('entity.memory_cache'),
$container->get('entity_type.bundle.info'),
$container->get('entity_type.manager'),
$container->get('entity.last_installed_schema.repository')
);
}
......
......@@ -70,7 +70,7 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_definition,
$migration,
$container->get('entity.manager')->getStorage($entity_type),
array_keys($container->get('entity.manager')->getBundleInfo($entity_type)),
array_keys($container->get('entity_type.bundle.info')->getBundleInfo($entity_type)),
$container->get('entity.manager'),
$container->get('plugin.manager.field.field_type'),
$container->get('state')
......
......@@ -61,7 +61,7 @@ protected function setUp() {
$this->addDefaultCommentField('entity_test', 'entity_test');
// Verify that bundles are defined correctly.
$bundles = \Drupal::entityManager()->getBundleInfo('comment');
$bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo('comment');
$this->assertEqual($bundles['comment']['label'], 'Comment settings');
// Create test user.
......
......@@ -2,16 +2,24 @@
namespace Drupal\config_translation\Controller;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines the config translation list builder for field entities.
*/
class ConfigTranslationFieldListBuilder extends ConfigTranslationEntityListBuilder {
use DeprecatedServicePropertyTrait;
/**
* {@inheritdoc}
*/
protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
/**
* The name of the entity type the fields are attached to.
......@@ -23,9 +31,9 @@ class ConfigTranslationFieldListBuilder extends ConfigTranslationEntityListBuild
/**
* An array containing the base entity type's definition.
*
* @var array
* @var \Drupal\Core\Entity\EntityTypeInterface
*/
protected $baseEntityInfo = [];
protected $baseEntityInfo;
/**
* The bundle info for the base entity type.
......@@ -35,21 +43,28 @@ class ConfigTranslationFieldListBuilder extends ConfigTranslationEntityListBuild
protected $baseEntityBundles = [];
/**
* The entity manager.
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityManager;
protected $entityTypeManager;
/**
* The entity bundle info.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
$entity_manager = $container->get('entity.manager');
$entity_type_manager = $container->get('entity_type.manager');
return new static(
$entity_type,
$entity_manager->getStorage($entity_type->id()),
$entity_manager
$entity_type_manager->getStorage($entity_type->id()),
$entity_type_manager
);
}
......@@ -60,12 +75,19 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
* @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\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle info.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, EntityManagerInterface $entity_manager) {
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL) {
parent::__construct($entity_type, $storage);
$this->entityManager = $entity_manager;
$this->entityTypeManager = $entity_type_manager;
if (!$entity_type_bundle_info) {
@trigger_error('Calling ConfigTranslationFieldListBuilder::__construct() with the $entity_type_bundle_info 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_type_bundle_info = \Drupal::service('entity_type.bundle.info');
}
$this->entityTypeBundleInfo = $entity_type_bundle_info;
}
/**
......@@ -73,8 +95,8 @@ public function __construct(EntityTypeInterface $entity_type, EntityStorageInter
*/
public function setMapperDefinition($mapper_definition) {
$this->baseEntityType = $mapper_definition['base_entity_type'];
$this->baseEntityInfo = $this->entityManager->getDefinition($this->baseEntityType);
$this->baseEntityBundles = $this->entityManager->getBundleInfo($this->baseEntityType);
$this->baseEntityInfo = $this->entityTypeManager->getDefinition($this->baseEntityType);
$this->baseEntityBundles = $this->entityTypeBundleInfo->getBundleInfo($this->baseEntityType);
return $this;
}
......
......@@ -3,7 +3,9 @@
namespace Drupal\content_translation;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -13,13 +15,26 @@
class ContentTranslationPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
use DeprecatedServicePropertyTrait;
/**
* The entity manager.
* {@inheritdoc}
*/
protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
protected $entityTypeManager;
/**
* The entity bundle info.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* The content translation manager.
......@@ -31,14 +46,21 @@ class ContentTranslationPermissions implements ContainerInjectionInterface {
/**
* Constructs a ContentTranslationPermissions instance.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\content_translation\ContentTranslationManagerInterface $content_translation_manager
* The content translation manager.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle info.
*/
public function __construct(EntityManagerInterface $entity_manager, ContentTranslationManagerInterface $content_translation_manager) {
$this->entityManager = $entity_manager;
public function __construct(EntityTypeManagerInterface $entity_type_manager, ContentTranslationManagerInterface $content_translation_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL) {
$this->entityTypeManager = $entity_type_manager;
$this->contentTranslationManager = $content_translation_manager;
if (!$entity_type_bundle_info) {
@trigger_error('Calling ContentTranslationPermissions::__construct() with the $entity_type_bundle_info 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_type_bundle_info = \Drupal::service('entity_type.bundle.info');
}
$this->entityTypeBundleInfo = $entity_type_bundle_info;
}
/**
......@@ -46,8 +68,9 @@ public function __construct(EntityManagerInterface $entity_manager, ContentTrans
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager'),
$container->get('content_translation.manager')
$container->get('entity_type.manager'),
$container->get('content_translation.manager'),
$container->get('entity_type.bundle.info')
);
}
......@@ -60,13 +83,13 @@ public function contentPermissions() {
$permission = [];
// Create a translate permission for each enabled entity type and (optionally)
// bundle.
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
if ($permission_granularity = $entity_type->getPermissionGranularity()) {
$t_args = ['@entity_label' => $entity_type->getLowercaseLabel()];
switch ($permission_granularity) {
case 'bundle':
foreach ($this->entityManager->getBundleInfo($entity_type_id) as $bundle => $bundle_info) {
foreach ($this->entityTypeBundleInfo->getBundleInfo($entity_type_id) as $bundle => $bundle_info) {
if ($this->contentTranslationManager->isEnabled($entity_type_id, $bundle)) {
$t_args['%bundle_label'] = isset($bundle_info['label']) ? $bundle_info['label'] : $bundle;
$permission["translate $bundle $entity_type_id"] = [
......
......@@ -4,7 +4,7 @@
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Entity\EntityDeleteForm;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\field_ui\FieldUI;
......@@ -18,20 +18,20 @@
class FieldConfigDeleteForm extends EntityDeleteForm {
/**
* The entity manager.
* The entity type bundle info service.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityManager;
protected $entityTypeBundleInfo;
/**
* Constructs a new FieldConfigDeleteForm object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle info service.
*/
public function __construct(EntityManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
public function __construct(EntityTypeBundleInfoInterface $entity_type_bundle_info) {
$this->entityTypeBundleInfo = $entity_type_bundle_info;
}
/**
......@@ -39,7 +39,7 @@ public function __construct(EntityManagerInterface $entity_manager) {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager')
$container->get('entity_type.bundle.info')
);
}
......@@ -93,7 +93,7 @@ public function getCancelUrl() {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$field_storage = $this->entity->getFieldStorageDefinition();
$bundles = $this->entityManager->getBundleInfo($this->entity->getTargetEntityTypeId());
$bundles = $this->entityTypeBundleInfo->getBundleInfo($this->entity->getTargetEntityTypeId());
$bundle_label = $bundles[$this->entity->getTargetBundle()]['label'];
if ($field_storage && !$field_storage->isLocked()) {
......
......@@ -3,12 +3,14 @@
namespace Drupal\field_ui\Form;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Field\AllowedTagsXssTrait;
use Drupal\Core\Field\FieldFilteredMarkup;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\field\FieldConfigInterface;
use Drupal\field_ui\FieldUI;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a form for the field settings form.
......@@ -26,6 +28,32 @@ class FieldConfigEditForm extends EntityForm {
*/
protected $entity;
/**
* The entity type bundle info service.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* Constructs a new FieldConfigDeleteForm object.
*
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle info service.
*/
public function __construct(EntityTypeBundleInfoInterface $entity_type_bundle_info) {
$this->entityTypeBundleInfo = $entity_type_bundle_info;
}