Issue #3006409 by Berdir: Update deprecated usages of Entity::getEntityManager()

8.7.x
Nathaniel Catchpole 2019-01-04 11:52:43 +00:00
parent db41bebece
commit 05bbd9d036
8 changed files with 27 additions and 26 deletions

View File

@ -19,13 +19,13 @@ abstract class ConfigEntityBundleBase extends ConfigEntityBase {
protected function deleteDisplays() {
// Remove entity displays of the deleted bundle.
if ($displays = $this->loadDisplays('entity_view_display')) {
$storage = $this->entityManager()->getStorage('entity_view_display');
$storage = $this->entityTypeManager()->getStorage('entity_view_display');
$storage->delete($displays);
}
// Remove entity form displays of the deleted bundle.
if ($displays = $this->loadDisplays('entity_form_display')) {
$storage = $this->entityManager()->getStorage('entity_form_display');
$storage = $this->entityTypeManager()->getStorage('entity_form_display');
$storage->delete($displays);
}
}
@ -36,20 +36,20 @@ abstract class ConfigEntityBundleBase extends ConfigEntityBase {
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);
$entity_manager = $this->entityManager();
$entity_type_manager = $this->entityTypeManager();
$bundle_of = $this->getEntityType()->getBundleOf();
if (!$update) {
$entity_manager->onBundleCreate($this->id(), $bundle_of);
\Drupal::service('entity_bundle.listener')->onBundleCreate($this->id(), $bundle_of);
}
else {
// Invalidate the render cache of entities for which this entity
// is a bundle.
if ($entity_manager->hasHandler($bundle_of, 'view_builder')) {
$entity_manager->getViewBuilder($bundle_of)->resetCache();
if ($entity_type_manager->hasHandler($bundle_of, 'view_builder')) {
$entity_type_manager->getViewBuilder($bundle_of)->resetCache();
}
// Entity bundle field definitions may depend on bundle settings.
$entity_manager->clearCachedFieldDefinitions();
$entity_manager->clearCachedBundles();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
$this->entityTypeBundleInfo()->clearCachedBundles();
}
}
@ -106,7 +106,7 @@ abstract class ConfigEntityBundleBase extends ConfigEntityBase {
->condition('id', $this->getEntityType()->getBundleOf() . '.' . $this->getOriginalId() . '.', 'STARTS_WITH')
->execute();
if ($ids) {
$storage = $this->entityManager()->getStorage($entity_type_id);
$storage = $this->entityTypeManager()->getStorage($entity_type_id);
return $storage->loadMultiple($ids);
}
return [];

View File

@ -429,7 +429,7 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
public function isTranslatable() {
// Check the bundle is translatable, the entity has a language defined, and
// the site has more than one language.
$bundles = $this->entityManager()->getBundleInfo($this->entityTypeId);
$bundles = $this->entityTypeBundleInfo()->getBundleInfo($this->entityTypeId);
return !empty($bundles[$this->bundle()]['translatable']) && !$this->getUntranslated()->language()->isLocked() && $this->languageManager()->isMultilingual();
}
@ -679,7 +679,7 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
*/
public function getFieldDefinitions() {
if (!isset($this->fieldDefinitions)) {
$this->fieldDefinitions = $this->entityManager()->getFieldDefinitions($this->entityTypeId, $this->bundle());
$this->fieldDefinitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->entityTypeId, $this->bundle());
}
return $this->fieldDefinitions;
}
@ -700,11 +700,11 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
*/
public function access($operation, AccountInterface $account = NULL, $return_as_object = FALSE) {
if ($operation == 'create') {
return $this->entityManager()
return $this->entityTypeManager()
->getAccessControlHandler($this->entityTypeId)
->createAccess($this->bundle(), $account, [], $return_as_object);
}
return $this->entityManager()
return $this->entityTypeManager()
->getAccessControlHandler($this->entityTypeId)
->access($this, $operation, $account, $return_as_object);
}
@ -960,7 +960,7 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
// Initialize the translation object.
/** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
$storage = $this->entityManager()->getStorage($this->getEntityTypeId());
$storage = $this->entityTypeManager()->getStorage($this->getEntityTypeId());
$this->translations[$langcode]['status'] = !isset($this->translations[$langcode]['status_existed']) ? static::TRANSLATION_CREATED : static::TRANSLATION_EXISTING;
return $storage->createTranslation($this, $langcode, $values);
}
@ -1411,7 +1411,7 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
if (!$original) {
$id = $this->getOriginalId() !== NULL ? $this->getOriginalId() : $this->id();
$original = $this->entityManager()->getStorage($this->getEntityTypeId())->loadUnchanged($id);
$original = $this->entityTypeManager()->getStorage($this->getEntityTypeId())->loadUnchanged($id);
}
// If the current translation has just been added, we have a change.

View File

@ -76,6 +76,7 @@ abstract class Entity implements EntityInterface {
* correct interface or service.
*/
protected function entityManager() {
@trigger_error('Entity::getEntityManager() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use ::getEntityTypeManager() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
return \Drupal::entityManager();
}

View File

@ -289,7 +289,7 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
*/
public function calculateDependencies() {
parent::calculateDependencies();
$target_entity_type = $this->entityManager()->getDefinition($this->targetEntityType);
$target_entity_type = $this->entityTypeManager()->getDefinition($this->targetEntityType);
// Create dependency on the bundle.
$bundle_config_dependency = $target_entity_type->getBundleConfigDependency($this->bundle);
@ -300,7 +300,7 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
// field overrides, since the field still exists without them.
if (\Drupal::moduleHandler()->moduleExists('field')) {
$components = $this->content + $this->hidden;
$field_definitions = $this->entityManager()->getFieldDefinitions($this->targetEntityType, $this->bundle);
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->targetEntityType, $this->bundle);
foreach (array_intersect_key($field_definitions, $components) as $field_name => $field_definition) {
if ($field_definition instanceof ConfigEntityInterface && $field_definition->getEntityTypeId() == 'field_config') {
$this->addDependency('config', $field_definition->getConfigDependencyName());
@ -310,7 +310,7 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
// Depend on configured modes.
if ($this->mode != 'default') {
$mode_entity = $this->entityManager()->getStorage('entity_' . $this->displayContext . '_mode')->load($target_entity_type->id() . '.' . $this->mode);
$mode_entity = $this->entityTypeManager()->getStorage('entity_' . $this->displayContext . '_mode')->load($target_entity_type->id() . '.' . $this->mode);
$this->addDependency('config', $mode_entity->getConfigDependencyName());
}
return $this;

View File

@ -163,7 +163,7 @@ class BaseFieldOverride extends FieldConfigBase {
*/
protected function getBaseFieldDefinition() {
if (!isset($this->baseFieldDefinition)) {
$fields = $this->entityManager()->getBaseFieldDefinitions($this->entity_type);
$fields = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions($this->entity_type);
$this->baseFieldDefinition = $fields[$this->getName()];
}
return $this->baseFieldDefinition;
@ -204,7 +204,7 @@ class BaseFieldOverride extends FieldConfigBase {
$previous_definition = $this->original;
}
// Notify the entity storage.
$this->entityManager()->getStorage($this->getTargetEntityTypeId())->onFieldDefinitionUpdate($this, $previous_definition);
$this->entityTypeManager()->getStorage($this->getTargetEntityTypeId())->onFieldDefinitionUpdate($this, $previous_definition);
}
/**

View File

@ -246,7 +246,7 @@ abstract class FieldConfigBase extends ConfigEntityBase implements FieldConfigIn
$this->addDependencies($definition['class']::calculateDependencies($this));
// Create dependency on the bundle.
$bundle_config_dependency = $this->entityManager()->getDefinition($this->entity_type)->getBundleConfigDependency($this->bundle);
$bundle_config_dependency = $this->entityTypeManager()->getDefinition($this->entity_type)->getBundleConfigDependency($this->bundle);
$this->addDependency($bundle_config_dependency['type'], $bundle_config_dependency['name']);
return $this;
@ -283,12 +283,12 @@ abstract class FieldConfigBase extends ConfigEntityBase implements FieldConfigIn
*/
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
// Clear the cache.
$this->entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// Invalidate the render cache for all affected entities.
$entity_type = $this->getFieldStorageDefinition()->getTargetEntityTypeId();
if ($this->entityManager()->hasHandler($entity_type, 'view_builder')) {
$this->entityManager()->getViewBuilder($entity_type)->resetCache();
if ($this->entityTypeManager()->hasHandler($entity_type, 'view_builder')) {
$this->entityTypeManager()->getViewBuilder($entity_type)->resetCache();
}
}

View File

@ -296,7 +296,7 @@ class FieldConfig extends FieldConfigBase implements FieldConfigInterface {
if (!$this->fieldStorage) {
$field_storage_definition = NULL;
$field_storage_definitions = $this->entityManager()->getFieldStorageDefinitions($this->entity_type);
$field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($this->entity_type);
if (isset($field_storage_definitions[$this->field_name])) {
$field_storage_definition = $field_storage_definitions[$this->field_name];
}

View File

@ -198,7 +198,7 @@ class NodeType extends ConfigEntityBundleBase implements NodeTypeInterface {
if ($update) {
// Clear the cached field definitions as some settings affect the field
// definitions.
$this->entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
}
}