Commit 05bbd9d0 authored by catch's avatar catch
Browse files

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

parent db41bebe
......@@ -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 @@ protected function deleteDisplays() {
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 @@ protected function loadDisplays($entity_type_id) {
->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 [];
......
......@@ -429,7 +429,7 @@ public function getRevisionId() {
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 @@ public function getFieldDefinition($name) {
*/
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 @@ public function toArray() {
*/
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 @@ public function addTranslation($langcode, array $values = []) {
// 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 @@ public function hasTranslationChanges() {
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.
......
......@@ -76,6 +76,7 @@ public function __construct(array $values, $entity_type) {
* 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();
}
......
......@@ -289,7 +289,7 @@ protected function handleHiddenType($name, array $component) {
*/
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 @@ public function calculateDependencies() {
// 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 @@ public function calculateDependencies() {
// 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;
......
......@@ -163,7 +163,7 @@ public function getUniqueIdentifier() {
*/
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 @@ public function preSave(EntityStorageInterface $storage) {
$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);
}
/**
......
......@@ -246,7 +246,7 @@ public function calculateDependencies() {
$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 @@ public function postCreate(EntityStorageInterface $storage) {
*/
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();
}
}
......
......@@ -296,7 +296,7 @@ public function getFieldStorageDefinition() {
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];
}
......
......@@ -198,7 +198,7 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
if ($update) {
// Clear the cached field definitions as some settings affect the field
// definitions.
$this->entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
}
}
......
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