diff --git a/core/modules/editor/lib/Drupal/editor/Entity/Editor.php b/core/modules/editor/lib/Drupal/editor/Entity/Editor.php index 0ec778e..ec50237 100644 --- a/core/modules/editor/lib/Drupal/editor/Entity/Editor.php +++ b/core/modules/editor/lib/Drupal/editor/Entity/Editor.php @@ -61,6 +61,11 @@ class Editor extends ConfigEntityBase implements EditorInterface { protected $filterFormat; /** + * @var \Drupal\Component\Plugin\PluginManagerInterface + */ + protected $editorPluginManager; + + /** * {@inheritdoc} */ public function id() { @@ -73,8 +78,7 @@ public function id() { public function __construct(array $values, $entity_type) { parent::__construct($values, $entity_type); - $manager = \Drupal::service('plugin.manager.editor'); - $plugin = $manager->createInstance($this->editor); + $plugin = $this->editorPluginManager()->createInstance($this->editor); // Initialize settings, merging module-provided defaults. $default_settings = $plugin->getDefaultSettings(); @@ -89,11 +93,10 @@ public function __construct(array $values, $entity_type) { public function calculateDependencies() { parent::calculateDependencies(); // Create a dependency of the linked filter. - $filter = entity_load('filter_format', $this->format); - $this->addDependency('entity', $filter->getConfigDependencyName()); + $this->addDependency('entity', $this->getFilterFormat()->getConfigDependencyName()); // @todo use EntityWithPluginBagInterface so configuration between config // entity and dependency on provider is managed automatically. - $definition = \Drupal::service('plugin.manager.editor')->createInstance($this->editor)->getPluginDefinition(); + $definition = $this->editorPluginManager()->createInstance($this->editor)->getPluginDefinition(); $this->addDependency('module', $definition['provider']); } @@ -102,9 +105,22 @@ public function calculateDependencies() { */ public function getFilterFormat() { if (!$this->filterFormat) { - $this->filterFormat = \Drupal::entityManager()->getStorageController('filter_format')->load($this->format); + $this->filterFormat = $this->entityManager()->getStorageController('filter_format')->load($this->format); } return $this->filterFormat; } + /** + * Returns the editor plugin manager. + * + * @return \Drupal\Component\Plugin\PluginManagerInterface + */ + protected function editorPluginManager() { + if (!$this->editorPluginManager) { + $this->editorPluginManager = \Drupal::service('plugin.manager.editor'); + } + + return $this->editorPluginManager; + } + } diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php index d54411b..76e7bf7 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php @@ -152,12 +152,12 @@ public function preSave(EntityStorageControllerInterface $storage_controller, $u */ public function calculateDependencies() { parent::calculateDependencies(); - $target_entity_type = \Drupal::entityManager()->getDefinition($this->targetEntityType); + $target_entity_type = $this->entityManager()->getDefinition($this->targetEntityType); $bundle_entity_type_id = $target_entity_type->getBundleEntityType(); if ($bundle_entity_type_id != 'bundle') { // If the target entity type uses bundles the depend on the bundle entity. - $bundle_entity = entity_load($bundle_entity_type_id, $this->bundle); + $bundle_entity = $this->entityManager()->getStorageController($bundle_entity_type_id)->load($this->bundle); $this->addDependency('entity', $bundle_entity->getConfigDependencyName()); } // Create dependencies on both hidden and visible fields. @@ -174,7 +174,7 @@ public function calculateDependencies() { } // Depend on configured modes. if ($this->mode != 'default') { - $mode_entity = entity_load($this->displayContext . '_mode', $target_entity_type->id() . '.' . $this->mode); + $mode_entity = $this->entityManager()->getStorageController($this->displayContext . '_mode')->load($target_entity_type->id() . '.' . $this->mode); $this->addDependency('entity', $mode_entity->getConfigDependencyName()); } } @@ -354,12 +354,12 @@ protected function getFieldDefinition($field_name) { protected function getFieldDefinitions() { // Entity displays are sometimes created for non-content entities. // @todo Prevent this in https://drupal.org/node/2095195. - if (!\Drupal::entityManager()->getDefinition($this->targetEntityType)->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) { + if (!$this->entityManager()->getDefinition($this->targetEntityType)->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) { return array(); } if (!isset($this->fieldDefinitions)) { - $definitions = \Drupal::entityManager()->getFieldDefinitions($this->targetEntityType, $this->bundle); + $definitions = $this->entityManager()->getFieldDefinitions($this->targetEntityType, $this->bundle); // The display only cares about fields that specify display options. // Discard base fields that are not rendered through formatters / widgets. diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php index ef30e6e..f57bef8 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php @@ -83,7 +83,7 @@ public function getTargetType() { */ public function calculateDependencies() { parent::calculateDependencies(); - $target_entity_type = \Drupal::entityManager()->getDefinition($this->targetEntityType); + $target_entity_type = $this->entityManager()->getDefinition($this->targetEntityType); $this->addDependency('module', $target_entity_type->getProvider()); } diff --git a/core/modules/picture/lib/Drupal/picture/Entity/PictureMapping.php b/core/modules/picture/lib/Drupal/picture/Entity/PictureMapping.php index 4fa90f1..174f624 100644 --- a/core/modules/picture/lib/Drupal/picture/Entity/PictureMapping.php +++ b/core/modules/picture/lib/Drupal/picture/Entity/PictureMapping.php @@ -87,7 +87,7 @@ public function calculateDependencies() { // @todo Implement getExportProperties() so we do not have reload the // entity since this property is changed in // \Drupal\picture\PictureMapping::save(). - $breakpoint_group = entity_load('breakpoint_group', $this->breakpointGroup); + $breakpoint_group = $this->entityManager()->getStorageController('breakpoint_group')->load($this->breakpointGroup); $this->addDependency('entity', $breakpoint_group->getConfigDependencyName()); } } diff --git a/core/modules/rdf/lib/Drupal/rdf/Entity/RdfMapping.php b/core/modules/rdf/lib/Drupal/rdf/Entity/RdfMapping.php index 8a3fa2c..1e56cb9 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Entity/RdfMapping.php +++ b/core/modules/rdf/lib/Drupal/rdf/Entity/RdfMapping.php @@ -161,12 +161,12 @@ public function getExportProperties() { */ public function calculateDependencies() { parent::calculateDependencies(); - $entity_type = \Drupal::entityManager()->getDefinition($this->targetEntityType); + $entity_type = $this->entityManager()->getDefinition($this->targetEntityType); $this->addDependency('module', $entity_type->getProvider()); $bundle_entity_type_id = $entity_type->getBundleEntityType(); if ($bundle_entity_type_id != 'bundle') { // If the target entity type uses bundles the depend on the bundle entity. - $bundle_entity = entity_load($bundle_entity_type_id, $this->bundle); + $bundle_entity = $this->entityManager()->getStorageController($bundle_entity_type_id)->load($this->bundle); $this->addDependency('entity', $bundle_entity->getConfigDependencyName()); } }