core/modules/node/src/Plugin/views/row/Rss.php | 23 +++------ .../src/Plugin/views/filter/TaxonomyIndexTid.php | 58 ++++++++++++++++++++-- .../src/Plugin/views/relationship/NodeTermData.php | 42 +++++++++++++++- core/modules/user/src/Plugin/views/access/Role.php | 42 +++++++++++++++- core/modules/views/src/Plugin/views/area/View.php | 2 +- .../src/Plugin/views/argument_validator/Entity.php | 4 +- .../views/src/Plugin/views/display/Page.php | 49 ++++++++++++++++++ .../views/src/Plugin/views/filter/Bundle.php | 39 +++++++++++++++ .../views/src/Plugin/views/row/EntityRow.php | 2 +- .../views/src/Plugin/views/row/RssPluginBase.php | 41 ++++++++++++++- 10 files changed, 272 insertions(+), 30 deletions(-) diff --git a/core/modules/node/src/Plugin/views/row/Rss.php b/core/modules/node/src/Plugin/views/row/Rss.php index f2f5a50..0b1acac 100644 --- a/core/modules/node/src/Plugin/views/row/Rss.php +++ b/core/modules/node/src/Plugin/views/row/Rss.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\String; +use Drupal\Core\Entity\EntityManagerInterface; use Drupal\views\Plugin\views\row\RssPluginBase; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\node\NodeStorageInterface; @@ -58,24 +59,12 @@ class Rss extends RssPluginBase { * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. - * @param NodeStorageInterface $node_storage - * The node storage. + * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager + * The entity manager. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, NodeStorageInterface $node_storage) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->nodeStorage = $node_storage; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('entity.manager')->getStorage('node') - ); + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_manager); + $this->nodeStorage = $entity_manager->getStorage('node'); } /** diff --git a/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php index 9bad607..5d7252a 100644 --- a/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php @@ -7,13 +7,17 @@ namespace Drupal\taxonomy\Plugin\views\filter; +use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\taxonomy\Entity\Term; +use Drupal\taxonomy\TermStorageInterface; +use Drupal\taxonomy\VocabularyStorageInterface; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\filter\ManyToOne; use Drupal\Component\Utility\String; use Drupal\Component\Utility\Tags; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Filter by term id. @@ -28,6 +32,54 @@ class TaxonomyIndexTid extends ManyToOne { var $validated_exposed_input = NULL; /** + * The vocabulary storage. + * + * @var \Drupal\taxonomy\VocabularyStorageInterface + */ + protected $vocabularyStorage; + + /** + * The term storage. + * + * @var \Drupal\taxonomy\TermStorageInterface + */ + protected $termStorage; + + /** + * Constructs a TaxonomyIndexTid object. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\taxonomy\VocabularyStorageInterface $vocabulary_storage + * The vocabulary storage. + * @param \Drupal\taxonomy\TermStorageInterface $term_storage + * The term storage. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, VocabularyStorageInterface $vocabulary_storage, TermStorageInterface $term_storage) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->is_handler = TRUE; + $this->vocabularyStorage = $vocabulary_storage; + $this->termStorage = $term_storage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('entity.manager')->getStorage('taxonomy_vocabulary'), + $container->get('entity.manager')->getStorage('taxonomy_term') + ); + } + + /** * Overrides \Drupal\views\Plugin\views\filter\ManyToOne::init(). */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { @@ -380,13 +432,11 @@ public function getCacheContexts() { public function calculateDependencies() { $dependencies = parent::calculateDependencies(); - $vocabulary = \Drupal::entityManager()->getStorage('taxonomy_vocabulary') - ->load($this->options['vid']); + $vocabulary = $this->vocabularyStorage->load($this->options['vid']); $dependencies[$vocabulary->getConfigDependencyKey()][] = $vocabulary->getConfigDependencyName(); - $term_storage = \Drupal::entityManager()->getStorage('taxonomy_term'); foreach ($this->options['value'] as $tid) { - $term = $term_storage->load($tid); + $term = $this->termStorage->load($tid); $dependencies[$term->getConfigDependencyKey()][] = $term->getConfigDependencyName(); } diff --git a/core/modules/taxonomy/src/Plugin/views/relationship/NodeTermData.php b/core/modules/taxonomy/src/Plugin/views/relationship/NodeTermData.php index b363cdd..b57a940 100644 --- a/core/modules/taxonomy/src/Plugin/views/relationship/NodeTermData.php +++ b/core/modules/taxonomy/src/Plugin/views/relationship/NodeTermData.php @@ -8,9 +8,11 @@ namespace Drupal\taxonomy\Plugin\views\relationship; use Drupal\Core\Form\FormStateInterface; +use Drupal\taxonomy\VocabularyStorageInterface; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\relationship\RelationshipPluginBase; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Relationship handler to return the taxonomy terms of nodes. @@ -22,6 +24,43 @@ class NodeTermData extends RelationshipPluginBase { /** + * The vocabulary storage. + * + * @var \Drupal\taxonomy\VocabularyStorageInterface + */ + protected $vocabularyStorage; + + /** + * Constructs a NodeTermData object. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\taxonomy\VocabularyStorageInterface $vocabulary_storage + * The vocabulary storage. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, VocabularyStorageInterface $vocabulary_storage) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->is_handler = TRUE; + $this->vocabularyStorage = $vocabulary_storage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('entity.manager')->getStorage('taxonomy_vocabulary') + ); + } + + /** * Overrides \Drupal\views\Plugin\views\relationship\RelationshipPluginBase::init(). */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { @@ -119,9 +158,8 @@ public function query() { public function calculateDependencies() { $dependencies = parent::calculateDependencies(); - $vocabulary_storage = \Drupal::entityManager()->getStorage('taxonomy_vocabulary'); foreach ($this->options['vids'] as $vocabulary_id) { - if ($vocabulary = $vocabulary_storage->load($vocabulary_id)) { + if ($vocabulary = $this->vocabularyStorage->load($vocabulary_id)) { $dependencies[$vocabulary->getConfigDependencyKey()][] = $vocabulary->getConfigDependencyName(); } } diff --git a/core/modules/user/src/Plugin/views/access/Role.php b/core/modules/user/src/Plugin/views/access/Role.php index fe58b87..954ea4f 100644 --- a/core/modules/user/src/Plugin/views/access/Role.php +++ b/core/modules/user/src/Plugin/views/access/Role.php @@ -9,7 +9,9 @@ use Drupal\Component\Utility\String; use Drupal\Core\Form\FormStateInterface; +use Drupal\user\RoleStorageInterface; use Drupal\views\Plugin\views\access\AccessPluginBase; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Routing\Route; use Drupal\Core\Session\AccountInterface; @@ -32,6 +34,43 @@ class Role extends AccessPluginBase { protected $usesOptions = TRUE; /** + * The role storage. + * + * @var \Drupal\user\RoleStorageInterface + */ + protected $roleStorage; + + /** + * Constructs a Role object. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\user\RoleStorageInterface $role_storage + * The role storage. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, RoleStorageInterface $role_storage) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->is_handler = TRUE; + $this->roleStorage = $role_storage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('entity.manager')->getStorage('user_role') + ); + } + + /** * {@inheritdoc} */ public function access(AccountInterface $account) { @@ -98,9 +137,8 @@ public function validateOptionsForm(&$form, FormStateInterface $form_state) { public function calculateDependencies() { $dependencies = parent::calculateDependencies(); - $role_storage = \Drupal::entityManager()->getStorage('user_role'); foreach (array_keys($this->options['role']) as $rid) { - if ($role = $role_storage->load($rid)) { + if ($role = $this->roleStorage->load($rid)) { $dependencies[$role->getConfigDependencyKey()][] = $role->getConfigDependencyName(); } } diff --git a/core/modules/views/src/Plugin/views/area/View.php b/core/modules/views/src/Plugin/views/area/View.php index 013e613..4f3af1c 100644 --- a/core/modules/views/src/Plugin/views/area/View.php +++ b/core/modules/views/src/Plugin/views/area/View.php @@ -159,7 +159,7 @@ public function calculateDependencies() { list($view_id) = explode(':', $this->options['view_to_insert'], 2); if ($view_id) { - $view = \Drupal::entityManager()->getStorage('view')->load($view_id); + $view = $this->viewStorage->load($view_id); $dependencies[$view->getConfigDependencyKey()][] = $view->getConfigDependencyName(); } diff --git a/core/modules/views/src/Plugin/views/argument_validator/Entity.php b/core/modules/views/src/Plugin/views/argument_validator/Entity.php index 4638171..110b5bb 100644 --- a/core/modules/views/src/Plugin/views/argument_validator/Entity.php +++ b/core/modules/views/src/Plugin/views/argument_validator/Entity.php @@ -219,8 +219,8 @@ public function calculateDependencies() { $dependencies = parent::calculateDependencies(); $entity_type_id = $this->definition['entity_type']; - $bundle_entity_type = \Drupal::entityManager()->getDefinition($entity_type_id)->getBundleEntityType(); - $bundle_entity_storage = \Drupal::entityManager()->getStorage($bundle_entity_type); + $bundle_entity_type = $this->entityManager->getDefinition($entity_type_id)->getBundleEntityType(); + $bundle_entity_storage = $this->entityManager->getStorage($bundle_entity_type); foreach (array_keys($this->options['bundles']) as $bundle) { $bundle_entity = $bundle_entity_storage->load($bundle); diff --git a/core/modules/views/src/Plugin/views/display/Page.php b/core/modules/views/src/Plugin/views/display/Page.php index 8307482..540f6db 100644 --- a/core/modules/views/src/Plugin/views/display/Page.php +++ b/core/modules/views/src/Plugin/views/display/Page.php @@ -8,7 +8,11 @@ namespace Drupal\views\Plugin\views\display; use Drupal\Component\Utility\Xss; +use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\State\StateInterface; +use Drupal\Core\Routing\RouteProviderInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -38,6 +42,51 @@ class Page extends PathPluginBase { protected $usesAttachments = TRUE; /** + * The menu storage. + * + * @var \Drupal\Core\Entity\EntityStorageInterface + */ + protected $menuStorage; + + /** + * Constructs a Page object. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider + * The route provider. + * @param \Drupal\Core\State\StateInterface $state + * The state key value store. + * @param \Drupal\Core\Entity\EntityStorageInterface $menu_storage + * The menu storage. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteProviderInterface $route_provider, StateInterface $state, EntityStorageInterface $menu_storage) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $route_provider, $state); + + $this->routeProvider = $route_provider; + $this->state = $state; + $this->menuStorage = $menu_storage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('router.route_provider'), + $container->get('state'), + $container->get('entity.manager')->getStorage('menu') + ); + } + + /** * Overrides \Drupal\views\Plugin\views\display\PathPluginBase::defineOptions(). */ protected function defineOptions() { diff --git a/core/modules/views/src/Plugin/views/filter/Bundle.php b/core/modules/views/src/Plugin/views/filter/Bundle.php index 13853ef..cc3416d 100644 --- a/core/modules/views/src/Plugin/views/filter/Bundle.php +++ b/core/modules/views/src/Plugin/views/filter/Bundle.php @@ -8,8 +8,10 @@ namespace Drupal\views\Plugin\views\filter; use Drupal\Core\Config\Entity\ConfigEntityInterface; +use Drupal\Core\Entity\EntityManagerInterface; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Filter class which allows filtering by entity bundles. @@ -35,6 +37,43 @@ class Bundle extends InOperator { protected $entityType; /** + * The entity manager. + * + * @var \Drupal\Core\Entity\EntityManagerInterface + */ + protected $entityManager; + + /** + * Constructs a Bundle object. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager + * The entity manager. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + + $this->entityManager = $entity_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('entity.manager') + ); + } + + /** * Overrides \Drupal\views\Plugin\views\filter\InOperator::init(). */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { diff --git a/core/modules/views/src/Plugin/views/row/EntityRow.php b/core/modules/views/src/Plugin/views/row/EntityRow.php index eee2e27..7a24818 100644 --- a/core/modules/views/src/Plugin/views/row/EntityRow.php +++ b/core/modules/views/src/Plugin/views/row/EntityRow.php @@ -219,7 +219,7 @@ public function render($row) { public function calculateDependencies() { $dependencies = parent::calculateDependencies(); - $view_mode = \Drupal::entityManager() + $view_mode = $this->entityManager ->getStorage('entity_view_mode') ->load($this->entityTypeId . '.' . $this->options['view_mode']); if ($view_mode) { diff --git a/core/modules/views/src/Plugin/views/row/RssPluginBase.php b/core/modules/views/src/Plugin/views/row/RssPluginBase.php index 6a06c13..b8187be 100644 --- a/core/modules/views/src/Plugin/views/row/RssPluginBase.php +++ b/core/modules/views/src/Plugin/views/row/RssPluginBase.php @@ -7,7 +7,9 @@ namespace Drupal\views\Plugin\views\row; +use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormStateInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Base class for Views RSS row plugins. @@ -15,6 +17,43 @@ abstract class RssPluginBase extends RowPluginBase { /** + * The entity manager. + * + * @var \Drupal\Core\Entity\EntityManagerInterface + */ + protected $entityManager; + + /** + * Constructs a RssPluginBase object. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager + * The entity manager. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + + $this->entityManager = $entity_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('entity.manager') + ); + } + + /** * The ID of the entity type for which this is an RSS row plugin. * * @var string @@ -64,7 +103,7 @@ public function buildOptionsForm_summary_options() { public function calculateDependencies() { $dependencies = parent::calculateDependencies(); - $view_mode = \Drupal::entityManager() + $view_mode = $this->entityManager ->getStorage('entity_view_mode') ->load($this->entityTypeId . '.' . $this->options['view_mode']); if ($view_mode) {