Skip to content

Commit 81915a9

Browse files
committed
Issue #3025427 by Berdir, amateescu: Add @trigger_error() to deprecated EntityManager->EntityTypeBundleInfo methods
1 parent 4b68814 commit 81915a9

File tree

32 files changed

+487
-185
lines changed

32 files changed

+487
-185
lines changed

core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Drupal\Core\Cache\Cache;
66
use Drupal\Core\Cache\CacheBackendInterface;
77
use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface;
8+
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
89
use Drupal\Core\Field\FieldDefinitionInterface;
910
use Drupal\Core\Field\FieldStorageDefinitionInterface;
1011
use Drupal\Core\Language\LanguageInterface;
@@ -15,6 +16,12 @@
1516
* Base class for content entity storage handlers.
1617
*/
1718
abstract class ContentEntityStorageBase extends EntityStorageBase implements ContentEntityStorageInterface, DynamicallyFieldableEntityStorageInterface {
19+
use DeprecatedServicePropertyTrait;
20+
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
1825

1926
/**
2027
* The entity bundle key.
@@ -24,11 +31,18 @@ abstract class ContentEntityStorageBase extends EntityStorageBase implements Con
2431
protected $bundleKey = FALSE;
2532

2633
/**
27-
* The entity manager.
34+
* The entity field manager service.
2835
*
29-
* @var \Drupal\Core\Entity\EntityManagerInterface
36+
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
3037
*/
31-
protected $entityManager;
38+
protected $entityFieldManager;
39+
40+
/**
41+
* The entity bundle info.
42+
*
43+
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
44+
*/
45+
protected $entityTypeBundleInfo;
3246

3347
/**
3448
* Cache backend.
@@ -49,18 +63,25 @@ abstract class ContentEntityStorageBase extends EntityStorageBase implements Con
4963
*
5064
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
5165
* The entity type definition.
52-
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
53-
* The entity manager.
66+
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
67+
* The entity field manager.
5468
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
5569
* The cache backend to be used.
5670
* @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface|null $memory_cache
5771
* The memory cache backend.
72+
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
73+
* The entity type bundle info.
5874
*/
59-
public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, MemoryCacheInterface $memory_cache = NULL) {
75+
public function __construct(EntityTypeInterface $entity_type, EntityFieldManagerInterface $entity_field_manager, CacheBackendInterface $cache, MemoryCacheInterface $memory_cache = NULL, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL) {
6076
parent::__construct($entity_type, $memory_cache);
6177
$this->bundleKey = $this->entityType->getKey('bundle');
62-
$this->entityManager = $entity_manager;
78+
$this->entityFieldManager = $entity_field_manager;
6379
$this->cacheBackend = $cache;
80+
if (!$entity_type_bundle_info) {
81+
@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);
82+
$entity_type_bundle_info = \Drupal::service('entity_type.bundle.info');
83+
}
84+
$this->entityTypeBundleInfo = $entity_type_bundle_info;
6485
}
6586

6687
/**
@@ -69,9 +90,10 @@ public function __construct(EntityTypeInterface $entity_type, EntityManagerInter
6990
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
7091
return new static(
7192
$entity_type,
72-
$container->get('entity.manager'),
93+
$container->get('entity_field.manager'),
7394
$container->get('cache.entity'),
74-
$container->get('entity.memory_cache')
95+
$container->get('entity.memory_cache'),
96+
$container->get('entity_type.bundle.info')
7597
);
7698
}
7799

@@ -124,7 +146,7 @@ public function createWithSampleValues($bundle = FALSE, array $values = []) {
124146
if (!$bundle) {
125147
throw new EntityStorageException("No entity bundle was specified");
126148
}
127-
if (!array_key_exists($bundle, $this->entityManager->getBundleInfo($this->entityTypeId))) {
149+
if (!array_key_exists($bundle, $this->entityTypeBundleInfo->getBundleInfo($this->entityTypeId))) {
128150
throw new EntityStorageException(sprintf("Missing entity bundle. The \"%s\" bundle does not exist", $bundle));
129151
}
130152
$values[$bundle_key] = $bundle;
@@ -963,7 +985,7 @@ protected function populateAffectedRevisionTranslations(ContentEntityInterface $
963985
* The sanitized list of entity key values.
964986
*/
965987
protected function cleanIds(array $ids, $entity_key = 'id') {
966-
$definitions = $this->entityManager->getBaseFieldDefinitions($this->entityTypeId);
988+
$definitions = $this->entityFieldManager->getBaseFieldDefinitions($this->entityTypeId);
967989
$field_name = $this->entityType->getKey($entity_key);
968990
if ($field_name && $definitions[$field_name]->getType() == 'integer') {
969991
$ids = array_filter($ids, function ($id) {

core/lib/Drupal/Core/Entity/EntityManager.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,39 +306,42 @@ public function clearCachedFieldDefinitions() {
306306
/**
307307
* {@inheritdoc}
308308
*
309-
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
309+
* @deprecated in drupal:8.0.0, will be removed before drupal:9.0.0.
310310
* Use \Drupal\Core\Entity\EntityTypeBundleInfoInterface::clearCachedBundles()
311311
* instead.
312312
*
313313
* @see https://www.drupal.org/node/2549139
314314
*/
315315
public function clearCachedBundles() {
316+
@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);
316317
$this->container->get('entity_type.bundle.info')->clearCachedBundles();
317318
}
318319

319320
/**
320321
* {@inheritdoc}
321322
*
322-
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
323+
* @deprecated in drupal:8.0.0, will be removed before drupal:9.0.0.
323324
* Use \Drupal\Core\Entity\EntityTypeBundleInfoInterface::getBundleInfo()
324325
* instead.
325326
*
326327
* @see https://www.drupal.org/node/2549139
327328
*/
328329
public function getBundleInfo($entity_type_id) {
330+
@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);
329331
return $this->container->get('entity_type.bundle.info')->getBundleInfo($entity_type_id);
330332
}
331333

332334
/**
333335
* {@inheritdoc}
334336
*
335-
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
337+
* @deprecated in drupal:8.0.0, will be removed before drupal:9.0.0.
336338
* Use \Drupal\Core\Entity\EntityTypeBundleInfoInterface::getAllBundleInfo()
337339
* instead.
338340
*
339341
* @see https://www.drupal.org/node/2549139
340342
*/
341343
public function getAllBundleInfo() {
344+
@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);
342345
return $this->container->get('entity_type.bundle.info')->getAllBundleInfo();
343346
}
344347

core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
use Drupal\Core\Entity\ContentEntityStorageBase;
1313
use Drupal\Core\Entity\ContentEntityTypeInterface;
1414
use Drupal\Core\Entity\EntityBundleListenerInterface;
15+
use Drupal\Core\Entity\EntityFieldManagerInterface;
1516
use Drupal\Core\Entity\EntityInterface;
16-
use Drupal\Core\Entity\EntityManagerInterface;
17+
use Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface;
18+
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
19+
use Drupal\Core\Entity\EntityTypeManagerInterface;
1720
use Drupal\Core\Entity\EntityStorageException;
1821
use Drupal\Core\Entity\EntityTypeInterface;
1922
use Drupal\Core\Entity\Query\QueryInterface;
@@ -118,6 +121,20 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
118121
*/
119122
protected $languageManager;
120123

124+
/**
125+
* The entity type manager.
126+
*
127+
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
128+
*/
129+
protected $entityTypeManager;
130+
131+
/**
132+
* The entity last installed schema repository.
133+
*
134+
* @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface
135+
*/
136+
protected $entityLastInstalledSchemaRepository;
137+
121138
/**
122139
* Whether this storage should use the temporary table mapping.
123140
*
@@ -132,10 +149,13 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
132149
return new static(
133150
$entity_type,
134151
$container->get('database'),
135-
$container->get('entity.manager'),
152+
$container->get('entity_field.manager'),
136153
$container->get('cache.entity'),
137154
$container->get('language_manager'),
138-
$container->get('entity.memory_cache')
155+
$container->get('entity.memory_cache'),
156+
$container->get('entity_type.bundle.info'),
157+
$container->get('entity_type.manager'),
158+
$container->get('entity.last_installed_schema.repository')
139159
);
140160
}
141161

@@ -147,7 +167,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
147167
* name.
148168
*/
149169
public function getFieldStorageDefinitions() {
150-
return $this->entityManager->getBaseFieldDefinitions($this->entityTypeId);
170+
return $this->entityFieldManager->getBaseFieldDefinitions($this->entityTypeId);
151171
}
152172

153173
/**
@@ -157,19 +177,36 @@ public function getFieldStorageDefinitions() {
157177
* The entity type definition.
158178
* @param \Drupal\Core\Database\Connection $database
159179
* The database connection to be used.
160-
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
161-
* The entity manager.
180+
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
181+
* The entity field manager.
162182
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
163183
* The cache backend to be used.
164184
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
165185
* The language manager.
166186
* @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface|null $memory_cache
167187
* The memory cache backend to be used.
168-
*/
169-
public function __construct(EntityTypeInterface $entity_type, Connection $database, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache = NULL) {
170-
parent::__construct($entity_type, $entity_manager, $cache, $memory_cache);
188+
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
189+
* The entity type bundle info.
190+
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
191+
* The entity type manager.
192+
* @param \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository
193+
* The entity last installed schema repository.
194+
*/
195+
public function __construct(EntityTypeInterface $entity_type, Connection $database, EntityFieldManagerInterface $entity_field_manager, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache = NULL, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, EntityTypeManagerInterface $entity_type_manager = NULL, EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository = NULL) {
196+
parent::__construct($entity_type, $entity_field_manager, $cache, $memory_cache, $entity_type_bundle_info);
171197
$this->database = $database;
172198
$this->languageManager = $language_manager;
199+
if (!$entity_last_installed_schema_repository) {
200+
@trigger_error('Calling SqlContentEntityStorage::__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);
201+
$entity_last_installed_schema_repository = \Drupal::service('entity.last_installed_schema.repository');
202+
}
203+
$this->entityLastInstalledSchemaRepository = $entity_last_installed_schema_repository;
204+
if (!$entity_type_manager) {
205+
@trigger_error('Calling SqlContentEntityStorage::__construct() with the $entity_type_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);
206+
$entity_type_manager = \Drupal::entityTypeManager();
207+
}
208+
$this->entityTypeManager = $entity_type_manager;
209+
173210
$this->initTableLayout();
174211
}
175212

@@ -252,7 +289,7 @@ public function getRevisionDataTable() {
252289
protected function getStorageSchema() {
253290
if (!isset($this->storageSchema)) {
254291
$class = $this->entityType->getHandlerClass('storage_schema') ?: 'Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema';
255-
$this->storageSchema = new $class($this->entityManager, $this->entityType, $this, $this->database);
292+
$this->storageSchema = new $class($this->entityTypeManager, $this->entityType, $this, $this->database, $this->entityFieldManager, $this->entityLastInstalledSchemaRepository);
256293
}
257294
return $this->storageSchema;
258295
}
@@ -320,7 +357,7 @@ public function getTableMapping(array $storage_definitions = NULL) {
320357
// If we are using our internal storage definitions, which is our main use
321358
// case, we can statically cache the computed table mapping.
322359
if (!isset($this->tableMapping)) {
323-
$storage_definitions = $this->entityManager->getFieldStorageDefinitions($this->entityTypeId);
360+
$storage_definitions = $this->entityFieldManager->getFieldStorageDefinitions($this->entityTypeId);
324361

325362
$this->tableMapping = $this->getCustomTableMapping($this->entityType, $storage_definitions);
326363
}
@@ -851,7 +888,7 @@ protected function doSaveFieldItems(ContentEntityInterface $entity, array $names
851888
}
852889
else {
853890
$table_mapping = $this->getTableMapping();
854-
$storage_definitions = $this->entityManager->getFieldStorageDefinitions($this->entityTypeId);
891+
$storage_definitions = $this->entityFieldManager->getFieldStorageDefinitions($this->entityTypeId);
855892
$shared_table_fields = FALSE;
856893
$dedicated_table_fields = [];
857894

@@ -1180,7 +1217,7 @@ protected function loadFromDedicatedTables(array &$values, $load_from_revision)
11801217
$definitions = [];
11811218
$table_mapping = $this->getTableMapping();
11821219
foreach ($bundles as $bundle => $v) {
1183-
$definitions[$bundle] = $this->entityManager->getFieldDefinitions($this->entityTypeId, $bundle);
1220+
$definitions[$bundle] = $this->entityFieldManager->getFieldDefinitions($this->entityTypeId, $bundle);
11841221
foreach ($definitions[$bundle] as $field_name => $field_definition) {
11851222
$storage_definition = $field_definition->getFieldStorageDefinition();
11861223
if ($table_mapping->requiresDedicatedTableStorage($storage_definition)) {
@@ -1268,7 +1305,7 @@ protected function saveToDedicatedTables(ContentEntityInterface $entity, $update
12681305
$original = !empty($entity->original) ? $entity->original : NULL;
12691306

12701307
// Determine which fields should be actually stored.
1271-
$definitions = $this->entityManager->getFieldDefinitions($entity_type, $bundle);
1308+
$definitions = $this->entityFieldManager->getFieldDefinitions($entity_type, $bundle);
12721309
if ($names) {
12731310
$definitions = array_intersect_key($definitions, array_flip($names));
12741311
}
@@ -1373,7 +1410,7 @@ protected function saveToDedicatedTables(ContentEntityInterface $entity, $update
13731410
*/
13741411
protected function deleteFromDedicatedTables(ContentEntityInterface $entity) {
13751412
$table_mapping = $this->getTableMapping();
1376-
foreach ($this->entityManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle()) as $field_definition) {
1413+
foreach ($this->entityFieldManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle()) as $field_definition) {
13771414
$storage_definition = $field_definition->getFieldStorageDefinition();
13781415
if (!$table_mapping->requiresDedicatedTableStorage($storage_definition)) {
13791416
continue;
@@ -1401,7 +1438,7 @@ protected function deleteRevisionFromDedicatedTables(ContentEntityInterface $ent
14011438
$vid = $entity->getRevisionId();
14021439
if (isset($vid)) {
14031440
$table_mapping = $this->getTableMapping();
1404-
foreach ($this->entityManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle()) as $field_definition) {
1441+
foreach ($this->entityFieldManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle()) as $field_definition) {
14051442
$storage_definition = $field_definition->getFieldStorageDefinition();
14061443
if (!$table_mapping->requiresDedicatedTableStorage($storage_definition)) {
14071444
continue;
@@ -1508,7 +1545,7 @@ public function onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $
15081545
*/
15091546
public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition) {
15101547
$table_mapping = $this->getTableMapping(
1511-
$this->entityManager->getLastInstalledFieldStorageDefinitions($this->entityType->id())
1548+
$this->entityLastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions($this->entityType->id())
15121549
);
15131550

15141551
if ($table_mapping->requiresDedicatedTableStorage($storage_definition)) {
@@ -1686,7 +1723,7 @@ public function countFieldData($storage_definition, $as_bool = FALSE) {
16861723
// storage definition is added, so bypass the internal storage definitions
16871724
// and fetch the table mapping using the passed in storage definition.
16881725
// @todo Fix this in https://www.drupal.org/node/2705205.
1689-
$storage_definitions = $this->entityManager->getFieldStorageDefinitions($this->entityTypeId);
1726+
$storage_definitions = $this->entityFieldManager->getFieldStorageDefinitions($this->entityTypeId);
16901727
$storage_definitions[$storage_definition->getName()] = $storage_definition;
16911728
$table_mapping = $this->getTableMapping($storage_definitions);
16921729

0 commit comments

Comments
 (0)