diff --git a/core/modules/node/src/Plugin/views/row/Rss.php b/core/modules/node/src/Plugin/views/row/Rss.php index b97bb64..b4e535f 100644 --- a/core/modules/node/src/Plugin/views/row/Rss.php +++ b/core/modules/node/src/Plugin/views/row/Rss.php @@ -10,6 +10,7 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\views\Plugin\views\row\RssPluginBase; +use Drupal\views\ViewExecutableFactory; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\node\NodeStorageInterface; @@ -60,9 +61,11 @@ class Rss extends RssPluginBase { * The plugin implementation definition. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. + * @param \Drupal\views\ViewExecutableFactory $executable_factory + * The factory to load a view executable with. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_manager); + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager, ViewExecutableFactory $executable_factory) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_manager, $executable_factory); $this->nodeStorage = $entity_manager->getStorage('node'); } diff --git a/core/modules/views/src/Entity/View.php b/core/modules/views/src/Entity/View.php index 6d1514f..34b4ab0 100644 --- a/core/modules/views/src/Entity/View.php +++ b/core/modules/views/src/Entity/View.php @@ -229,7 +229,7 @@ public function &getDisplay($display_id) { * {@inheritdoc} */ public function duplicateDisplayAsType($old_display_id, $new_display_type) { - $executable = Views::executableFactory()->get($this); + $executable = $this->getExecutable(); $display = $executable->newDisplay($new_display_type); $new_display_id = $display->display['id']; $displays = $this->get('display'); @@ -266,7 +266,7 @@ public function calculateDependencies() { // Ensure that the view is dependant on the module that implements the view. $this->addDependency('module', $this->module); - $executable = Views::executableFactory()->get($this); + $executable = $this->getExecutable(); $executable->initDisplay(); $executable->initStyle(); @@ -308,7 +308,7 @@ public function preSave(EntityStorageInterface $storage) { * a view at save time rather than at runtime. */ protected function addCacheMetadata() { - $executable = Views::executableFactory()->get($this); + $executable = $this->getExecutable(); $current_display = $executable->current_display; $displays = $this->get('display'); diff --git a/core/modules/views/src/EventSubscriber/RouteSubscriber.php b/core/modules/views/src/EventSubscriber/RouteSubscriber.php index cdc1fd5..7185614 100644 --- a/core/modules/views/src/EventSubscriber/RouteSubscriber.php +++ b/core/modules/views/src/EventSubscriber/RouteSubscriber.php @@ -15,6 +15,7 @@ use Drupal\views\ViewExecutable; use Drupal\views\Views; use Symfony\Component\Routing\RouteCollection; +use Drupal\views\ViewExecutableFactory; use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; use Symfony\Component\HttpKernel\KernelEvents; @@ -52,6 +53,13 @@ class RouteSubscriber extends RouteSubscriberBase { protected $state; /** + * The factory to load a view executable with. + * + * @var \Drupal\views\ViewExecutableFactory + */ + protected $executableFactory; + + /** * Stores an array of route names keyed by view_id.display_id. * * @var array @@ -65,10 +73,13 @@ class RouteSubscriber extends RouteSubscriberBase { * The entity manager. * @param \Drupal\Core\State\StateInterface $state * The state key value store. + * @param \Drupal\views\ViewExecutableFactory $executable_factory + * The factory to load a view executable with. */ - public function __construct(EntityManagerInterface $entity_manager, StateInterface $state) { + public function __construct(EntityManagerInterface $entity_manager, StateInterface $state , ViewExecutableFactory $executable_factory) { $this->viewStorage = $entity_manager->getStorage('view'); $this->state = $state; + $this->executableFactory = $executable_factory; } /** @@ -121,8 +132,7 @@ public function routes() { foreach ($this->getViewsDisplayIDsWithRoute() as $pair) { list($view_id, $display_id) = explode('.', $pair); $view = $this->viewStorage->load($view_id); - // @todo This should have an executable factory injected. - if (($view = Views::executableFactory()->get($view)) && $view instanceof ViewExecutable) { + if (($view = $this->executableFactory->get($view)) && $view instanceof ViewExecutable) { if ($view->setDisplay($display_id) && $display = $view->displayHandlers->get($display_id)) { if ($display instanceof DisplayRouterInterface) { $this->viewRouteNames += (array) $display->collectRoutes($collection); @@ -143,8 +153,7 @@ protected function alterRoutes(RouteCollection $collection) { foreach ($this->getViewsDisplayIDsWithRoute() as $pair) { list($view_id, $display_id) = explode('.', $pair); $view = $this->viewStorage->load($view_id); - // @todo This should have an executable factory injected. - if (($view = Views::executableFactory()->get($view)) && $view instanceof ViewExecutable) { + if (($view = $this->executableFactory->get($view)) && $view instanceof ViewExecutable) { if ($view->setDisplay($display_id) && $display = $view->displayHandlers->get($display_id)) { if ($display instanceof DisplayRouterInterface) { // If the display returns TRUE a route item was found, so it does not diff --git a/core/modules/views/src/Plugin/Derivative/ViewsBlock.php b/core/modules/views/src/Plugin/Derivative/ViewsBlock.php index d5f489c..02502fd 100644 --- a/core/modules/views/src/Plugin/Derivative/ViewsBlock.php +++ b/core/modules/views/src/Plugin/Derivative/ViewsBlock.php @@ -9,8 +9,8 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; -use Drupal\views\Views; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\views\ViewExecutableFactory; /** * Provides block plugin definitions for all Views block displays. @@ -41,12 +41,20 @@ class ViewsBlock implements ContainerDeriverInterface { protected $viewStorage; /** + * The factory to load a view executable with. + * + * @var \Drupal\views\ViewExecutableFactory + */ + protected $executableFactory; + + /** * {@inheritdoc} */ public static function create(ContainerInterface $container, $base_plugin_id) { return new static( $base_plugin_id, - $container->get('entity.manager')->getStorage('view') + $container->get('entity.manager')->getStorage('view'), + $container->get('views.executable') ); } @@ -57,10 +65,13 @@ public static function create(ContainerInterface $container, $base_plugin_id) { * The base plugin ID. * @param \Drupal\Core\Entity\EntityStorageInterface $view_storage * The entity storage to load views. + * @param \Drupal\views\ViewExecutableFactory $executable_factory + * The factory to load a view executable with. */ - public function __construct($base_plugin_id, EntityStorageInterface $view_storage) { + public function __construct($base_plugin_id, EntityStorageInterface $view_storage, ViewExecutableFactory $executable_factory) { $this->basePluginId = $base_plugin_id; $this->viewStorage = $view_storage; + $this->executableFactory = $executable_factory; } /** @@ -84,7 +95,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { if (!$view->status()) { continue; } - $executable = Views::executableFactory()->get($view); + $executable = $this->executableFactory->get($view); $executable->initDisplay(); foreach ($executable->displayHandlers as $display) { // Add a block plugin definition for each block display. diff --git a/core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php b/core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php index 1b9079b..4b0a7d1 100644 --- a/core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php +++ b/core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php @@ -9,7 +9,7 @@ use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; use Drupal\Core\Entity\EntityStorageInterface; -use Drupal\views\Views; +use Drupal\views\ViewExecutableFactory; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -41,16 +41,26 @@ class ViewsExposedFilterBlock implements ContainerDeriverInterface { protected $basePluginId; /** + * The factory to load a view executable with. + * + * @var \Drupal\views\ViewExecutableFactory + */ + protected $executableFactory; + + /** * Constructs a ViewsExposedFilterBlock object. * * @param string $base_plugin_id * The base plugin ID. * @param \Drupal\Core\Entity\EntityStorageInterface $view_storage * The entity storage to load views. + * @param \Drupal\views\ViewExecutableFactory $executable_factory + * The factory to load a view executable with. */ - public function __construct($base_plugin_id, EntityStorageInterface $view_storage) { + public function __construct($base_plugin_id, EntityStorageInterface $view_storage, ViewExecutableFactory $executable_factory) { $this->basePluginId = $base_plugin_id; $this->viewStorage = $view_storage; + $this->executableFactory = $executable_factory; } /** @@ -59,7 +69,9 @@ public function __construct($base_plugin_id, EntityStorageInterface $view_storag public static function create(ContainerInterface $container, $base_plugin_id) { return new static( $base_plugin_id, - $container->get('entity.manager')->getStorage('view') + $container->get('entity.manager')->getStorage('view'), + $container->get('views.executable') + ); } @@ -84,7 +96,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { if (!$view->status()) { continue; } - $executable = Views::executableFactory()->get($view); + $executable = $this->executableFactory->get($view); $executable->initDisplay(); foreach ($executable->displayHandlers as $display) { if (isset($display) && $display->getOption('exposed_block')) { diff --git a/core/modules/views/src/Plugin/ViewsHandlerManager.php b/core/modules/views/src/Plugin/ViewsHandlerManager.php index 5244147..deae4a6 100644 --- a/core/modules/views/src/Plugin/ViewsHandlerManager.php +++ b/core/modules/views/src/Plugin/ViewsHandlerManager.php @@ -11,6 +11,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; +use Drupal\views\ViewExecutableFactory; use Drupal\views\ViewsData; use Symfony\Component\DependencyInjection\Container; use Drupal\views\Plugin\views\HandlerBase; @@ -37,6 +38,13 @@ class ViewsHandlerManager extends DefaultPluginManager implements FallbackPlugin protected $handlerType; /** + * The factory to load a view executable with. + * + * @var \Drupal\views\ViewExecutableFactory + */ + protected $executableFactory; + + /** * Constructs a ViewsHandlerManager object. * * @param string $handler_type @@ -50,8 +58,10 @@ class ViewsHandlerManager extends DefaultPluginManager implements FallbackPlugin * Cache backend instance to use. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler to invoke the alter hook with. + * @param \Drupal\views\ViewExecutableFactory $executable_factory + * The factory to load a view executable with. */ - public function __construct($handler_type, \Traversable $namespaces, ViewsData $views_data, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { + public function __construct($handler_type, \Traversable $namespaces, ViewsData $views_data, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ViewExecutableFactory $executable_factory) { $plugin_definition_annotation_name = 'Drupal\views\Annotation\Views' . Container::camelize($handler_type); $plugin_interface = 'Drupal\views\Plugin\views\ViewsHandlerInterface'; if ($handler_type == 'join') { @@ -67,6 +77,7 @@ public function __construct($handler_type, \Traversable $namespaces, ViewsData $ $this->defaults = array( 'plugin_type' => $handler_type, ); + $this->executableFactory = $executable_factory; } /** @@ -127,6 +138,7 @@ public function createInstance($plugin_id, array $configuration = array()) { if ($instance instanceof HandlerBase) { $instance->setModuleHandler($this->moduleHandler); $instance->setViewsData($this->viewsData); + $instance->setExecutableFactory($this->executableFactory); } return $instance; } diff --git a/core/modules/views/src/Plugin/views/HandlerBase.php b/core/modules/views/src/Plugin/views/HandlerBase.php index 4bff164..79ae997 100644 --- a/core/modules/views/src/Plugin/views/HandlerBase.php +++ b/core/modules/views/src/Plugin/views/HandlerBase.php @@ -18,6 +18,7 @@ use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ViewExecutable; use Drupal\Core\Database\Database; +use Drupal\views\ViewExecutableFactory; use Drupal\views\Views; use Drupal\views\ViewsData; @@ -93,6 +94,13 @@ protected $moduleHandler; /** + * The factory to load a view executable with. + * + * @var \Drupal\views\ViewExecutableFactory + */ + protected $executableFactory; + + /** * The views data service. * * @var \Drupal\views\ViewsData @@ -335,6 +343,29 @@ public function setModuleHandler(ModuleHandlerInterface $module_handler) { } /** + * Gets the executable factory. + * + * @return \Drupal\views\ViewExecutableFactory + */ + protected function getExecutableFactory() { + if (!$this->executableFactory) { + $this->executableFactory = Views::executableFactory(); + } + + return $this->executableFactory; + } + + /** + * Sets the executable factory. + * + * @param \Drupal\views\ViewExecutableFactory $executable_factory + * The factory to load a view executable with. + */ + public function setExecutableFactory(ViewExecutableFactory $executable_factory) { + $this->executableFactory = $executable_factory; + } + + /** * Provides the handler some groupby. */ public function usesGroupBy() { @@ -773,7 +804,7 @@ public function displayExposedForm($form, FormStateInterface $form_state) { $display_id = $form_state->get('display_id'); $type = $form_state->get('type'); $id = $form_state->get('id'); - Views::executableFactory()->get($view)->setHandler($display_id, $type, $id, $item); + $this->getExecutableFactory()->get($view)->setHandler($display_id, $type, $id, $item); $view->addFormToStack($form_state->get('form_key'), $display_id, $type, $id, TRUE, TRUE); @@ -802,7 +833,7 @@ public function submitTemporaryForm($form, FormStateInterface $form_state) { $override = NULL; $view = $form_state->get('view'); - $executable = Views::executableFactory()->get($view); + $executable = $this->getExecutableFactory()->get($view); if ($executable->display_handler->useGroupBy() && !empty($item['group_type'])) { if (empty($executable->query)) { $executable->initQuery(); @@ -827,7 +858,7 @@ public function submitTemporaryForm($form, FormStateInterface $form_state) { $handler->unpackOptions($handler->options, $options, NULL, FALSE); // Store the item back on the view. - $executable = Views::executableFactory()->get($view); + $executable = $this->getExecutableFactory()->get($view); $executable->temporary_options[$type][$form_state->get('id')] = $handler->options; // @todo Decide if \Drupal\views_ui\Form\Ajax\ViewsFormBase::getForm() is diff --git a/core/modules/views/src/Plugin/views/area/View.php b/core/modules/views/src/Plugin/views/area/View.php index d7ce2fc..2ec9b6a 100644 --- a/core/modules/views/src/Plugin/views/area/View.php +++ b/core/modules/views/src/Plugin/views/area/View.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\views\ViewExecutableFactory; use Drupal\views\Views; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -35,6 +36,13 @@ class View extends AreaPluginBase { */ protected $viewStorage; + /** + * The factory to load a view executable with. + * + * @var \Drupal\views\ViewExecutableFactory + */ + protected $executableFactory; + /** * Constructs a View object. * @@ -46,24 +54,28 @@ class View extends AreaPluginBase { * The plugin implementation definition. * @param \Drupal\Core\Entity\EntityStorageInterface $view_storage * The view storage. + * @param \Drupal\views\ViewExecutableFactory $executable_factory + * The factory to load a view executable with. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $view_storage) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $view_storage, ViewExecutableFactory $executable_factory) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->viewStorage = $view_storage; + $this->executableFactory = $executable_factory; } - /** - * {@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('view') - ); - } + /** + * {@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('view'), + $container->get('views.executable') + ); + } /** * {@inheritdoc} @@ -109,8 +121,7 @@ public function render($empty = FALSE) { if (!empty($this->options['view_to_insert'])) { list($view_name, $display_id) = explode(':', $this->options['view_to_insert']); - $view = $this->viewStorage->load($view_name); - $view = Views::executableFactory()->get($view); + $view = $this->executableFactory->get($this->viewStorage->load($view_name)); if (empty($view) || !$view->access($display_id)) { return array(); diff --git a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php index 890eb70..6e43a7e 100644 --- a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php +++ b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php @@ -17,7 +17,6 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ViewExecutable; -use Drupal\views\Views; /** * @defgroup views_filter_handlers Views filter handler plugins @@ -84,6 +83,8 @@ */ var $always_required = FALSE; + + /** * Overrides \Drupal\views\Plugin\views\HandlerBase::init(). * @@ -446,7 +447,7 @@ public function buildGroupForm($form, FormStateInterface $form_state) { $display_id = $form_state->get('display_id'); $type = $form_state->get('type'); $id = $form_state->get('id'); - Views::executableFactory()->get($view)->setHandler($display_id, $type, $id, $item); + $this->getExecutableFactory()->get($view)->setHandler($display_id, $type, $id, $item); $view->addFormToStack($form_state->get('form_key'), $display_id, $type, $id, TRUE, TRUE); @@ -1111,7 +1112,7 @@ public function addGroupForm($form, FormStateInterface $form_state) { $display_id = $form_state->get('display_id'); $type = $form_state->get('type'); $id = $form_state->get('id'); - Views::executableFactory()->get($view)->setHandler($display_id, $type, $id, $item); + $this->getExecutableFactory()->get($view)->setHandler($display_id, $type, $id, $item); $view->cacheSet(); $form_state->set('rerender', TRUE); diff --git a/core/modules/views/src/Plugin/views/relationship/GroupwiseMax.php b/core/modules/views/src/Plugin/views/relationship/GroupwiseMax.php index 1a6b1f3..5c4441a 100644 --- a/core/modules/views/src/Plugin/views/relationship/GroupwiseMax.php +++ b/core/modules/views/src/Plugin/views/relationship/GroupwiseMax.php @@ -9,7 +9,9 @@ use Drupal\Core\Database\Query\AlterableInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\views\ViewExecutableFactory; use Drupal\views\Views; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Relationship handler that allows a groupwise maximum of the linked in table. @@ -64,6 +66,42 @@ class GroupwiseMax extends RelationshipPluginBase { /** + * The factory to load a view executable with. + * + * @var \Drupal\views\ViewExecutableFactory + */ + protected $executableFactory; + + /** + * Constructs an GroupwiseMax 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\views\ViewExecutableFactory $executable_factory + * The factory to load a view executable with. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, ViewExecutableFactory $executable_factory) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->executableFactory = $executable_factory; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('views.executable') + ); + } + + /** * {@inheritdoc} */ protected function defineOptions() { @@ -158,7 +196,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { protected function getTemporaryView() { $view = entity_create('view', array('base_table' => $this->definition['base'])); $view->addDisplay('default'); - return Views::executableFactory()->get($view); + return $this->executableFactory->get($view); } /** diff --git a/core/modules/views/src/Plugin/views/row/EntityRow.php b/core/modules/views/src/Plugin/views/row/EntityRow.php index e95e5fa..732707d 100644 --- a/core/modules/views/src/Plugin/views/row/EntityRow.php +++ b/core/modules/views/src/Plugin/views/row/EntityRow.php @@ -14,6 +14,7 @@ use Drupal\views\Entity\Render\EntityTranslationRenderTrait; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ViewExecutable; +use Drupal\views\ViewExecutableFactory; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -76,9 +77,11 @@ class EntityRow extends RowPluginBase { * The entity manager. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. + * @param \Drupal\views\ViewExecutableFactory $executable_factory + * The factory to load a view executable with. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition); + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, ViewExecutableFactory $executable_factory) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $executable_factory); $this->entityManager = $entity_manager; $this->languageManager = $language_manager; @@ -100,7 +103,14 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o * {@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'), $container->get('language_manager')); + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('entity.manager'), + $container->get('language_manager'), + $container->get('views.executable') + ); } /** diff --git a/core/modules/views/src/Plugin/views/row/RowPluginBase.php b/core/modules/views/src/Plugin/views/row/RowPluginBase.php index 32fc4b3..b13a96b 100644 --- a/core/modules/views/src/Plugin/views/row/RowPluginBase.php +++ b/core/modules/views/src/Plugin/views/row/RowPluginBase.php @@ -10,7 +10,9 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\views\Plugin\views\PluginBase; use Drupal\views\ViewExecutable; +use Drupal\views\ViewExecutableFactory; use Drupal\views\Views; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * @defgroup views_row_plugins Views row plugins @@ -56,6 +58,42 @@ protected $usesFields = FALSE; /** + * The factory to load a view executable with. + * + * @var \Drupal\views\ViewExecutableFactory + */ + protected $executableFactory; + + /** + * Constructs a PluginBase 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\views\ViewExecutableFactory $executable_factory + * The factory to load a view executable with. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, ViewExecutableFactory $executable_factory) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->executableFactory = $executable_factory; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('views.executable') + ); + } + + /** * Returns the usesFields property. * * @return bool @@ -82,7 +120,7 @@ protected function defineOptions() { public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); if (isset($this->base_table)) { - $executable = Views::executableFactory()->get($form_state->get('view')); + $executable = $this->executableFactory->get($form_state->get('view')); // A whole bunch of code to figure out what relationships are valid for // this item. diff --git a/core/modules/views/src/Plugin/views/row/RssPluginBase.php b/core/modules/views/src/Plugin/views/row/RssPluginBase.php index ed1e5b9..11bbe05 100644 --- a/core/modules/views/src/Plugin/views/row/RssPluginBase.php +++ b/core/modules/views/src/Plugin/views/row/RssPluginBase.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\views\ViewExecutableFactory; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -35,8 +36,8 @@ * @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); + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager, ViewExecutableFactory $executable_factory) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $executable_factory); $this->entityManager = $entity_manager; } @@ -49,7 +50,8 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('entity.manager') + $container->get('entity.manager'), + $container->get('views.executable') ); } diff --git a/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php b/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php index 629bcec..0606c64 100644 --- a/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php +++ b/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php @@ -11,11 +11,13 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\UrlGeneratorTrait; use Drupal\views\Entity\View; +use Drupal\views\ViewExecutableFactory; use Drupal\views\Views; use Drupal\views_ui\ViewUI; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\PluginBase; use Drupal\views\Plugin\views\wizard\WizardInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * @defgroup views_wizard_plugins Views wizard plugins @@ -115,12 +117,29 @@ ); /** + * The factory to load a view executable with. + * + * @var \Drupal\views\ViewExecutableFactory + */ + protected $executableFactory; + + /** * Constructs a WizardPluginBase 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\views\ViewExecutableFactory $executable_factory + * The factory to load a view executable with. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, ViewExecutableFactory $executable_factory) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->base_table = $this->definition['base_table']; + $this->executableFactory = $executable_factory; $entity_types = \Drupal::entityManager()->getDefinitions(); foreach ($entity_types as $entity_type_id => $entity_type) { @@ -132,6 +151,18 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition } /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('views.executable') + ); + } + + /** * Gets the createdColumn property. * * @return string @@ -730,7 +761,7 @@ protected function alterDisplayOptions(&$display_options, $form, FormStateInterf protected function addDisplays(View $view, $display_options, $form, FormStateInterface $form_state) { // Initialize and store the view executable to get the display plugin // instances. - $executable = Views::executableFactory()->get($view); + $executable = $this->executableFactory->get($view); // Display: Master $default_display = $executable->newDisplay('default', 'Master', 'default'); @@ -1237,7 +1268,7 @@ protected function setValidatedView(array $form, FormStateInterface $form_state, */ public function validateView(array $form, FormStateInterface $form_state) { $view = $this->instantiateView($form, $form_state); - $errors = Views::executableFactory()->get($view)->validate(); + $errors = $this->executableFactory->get($view)->validate(); if (empty($errors)) { $this->setValidatedView($form, $form_state, $view); diff --git a/core/modules/views/src/Tests/DefaultViewsTest.php b/core/modules/views/src/Tests/DefaultViewsTest.php index 45dd319..4ef5091 100644 --- a/core/modules/views/src/Tests/DefaultViewsTest.php +++ b/core/modules/views/src/Tests/DefaultViewsTest.php @@ -117,7 +117,7 @@ public function testDefaultViews() { $views = $controller->loadMultiple(); foreach ($views as $name => $view_storage) { - $view = Views::executableFactory()->get($view_storage); + $view = $view_storage->getExecutable(); $view->initDisplay(); foreach ($view->storage->get('display') as $display_id => $display) { $view->setDisplay($display_id); diff --git a/core/modules/views/src/Tests/Handler/HandlerAllTest.php b/core/modules/views/src/Tests/Handler/HandlerAllTest.php index 0b9fbf9..c4c6497 100644 --- a/core/modules/views/src/Tests/Handler/HandlerAllTest.php +++ b/core/modules/views/src/Tests/Handler/HandlerAllTest.php @@ -9,7 +9,6 @@ use Drupal\comment\Tests\CommentTestTrait; use Drupal\views\ViewExecutable; -use Drupal\views\Views; use Drupal\views\Plugin\views\HandlerBase; use Drupal\views\Plugin\views\filter\InOperator; @@ -61,7 +60,7 @@ public function testHandlers() { } $view = entity_create('view', array('base_table' => $base_table)); - $view = Views::executableFactory()->get($view); + $view = $view->getExecutable(); // @todo The groupwise relationship is currently broken. $exclude[] = 'taxonomy_term_field_data:tid_representative'; diff --git a/core/modules/views/src/Tests/ModuleTest.php b/core/modules/views/src/Tests/ModuleTest.php index 93ec6b1..e237a19 100644 --- a/core/modules/views/src/Tests/ModuleTest.php +++ b/core/modules/views/src/Tests/ModuleTest.php @@ -195,7 +195,7 @@ public function testLoadFunctions() { // Test $exclude_view parameter. $this->assertFalse(array_key_exists('archive', Views::getViewsAsOptions(TRUE, 'all', 'archive')), 'View excluded from options based on name'); $this->assertFalse(array_key_exists('archive:default', Views::getViewsAsOptions(FALSE, 'all', 'archive:default')), 'View display excluded from options based on name'); - $this->assertFalse(array_key_exists('archive', Views::getViewsAsOptions(TRUE, 'all', Views::executableFactory()->get($archive))), 'View excluded from options based on object'); + $this->assertFalse(array_key_exists('archive', Views::getViewsAsOptions(TRUE, 'all', $archive->getExecutable())), 'View excluded from options based on object'); // Test the $opt_group parameter. $expected_opt_groups = array(); diff --git a/core/modules/views/src/Tests/Plugin/DisabledDisplayTest.php b/core/modules/views/src/Tests/Plugin/DisabledDisplayTest.php index dff61e8..e9052b4 100644 --- a/core/modules/views/src/Tests/Plugin/DisabledDisplayTest.php +++ b/core/modules/views/src/Tests/Plugin/DisabledDisplayTest.php @@ -7,8 +7,6 @@ namespace Drupal\views\Tests\Plugin; -use Drupal\views\Views; - /** * Tests the ability to disable and enable view displays. * @@ -56,7 +54,7 @@ public function testDisabledDisplays() { // Load the test view and initialize its displays. $view = $this->container->get('entity.manager')->getStorage('view')->load('test_disabled_display'); - Views::executableFactory()->get($view)->setDisplay(); + $view->getExecutable()->setDisplay(); // Enabled page display should return content. $this->drupalGet('test-disabled-display'); @@ -69,9 +67,9 @@ public function testDisabledDisplays() { // Enable each disabled display and save the view. foreach ($display_ids as $display_id) { - Views::executableFactory()->get($view)->displayHandlers->get($display_id)->setOption('enabled', TRUE); + $view->getExecutable()->displayHandlers->get($display_id)->setOption('enabled', TRUE); $view->save(); - $enabled = Views::executableFactory()->get($view)->displayHandlers->get($display_id)->isEnabled(); + $enabled = $view->getExecutable()->displayHandlers->get($display_id)->isEnabled(); $this->assertTrue($enabled, 'Display ' . $display_id . ' is now enabled'); } @@ -84,9 +82,9 @@ public function testDisabledDisplays() { // Disable each disabled display and save the view. foreach ($display_ids as $display_id) { - Views::executableFactory()->get($view)->displayHandlers->get($display_id)->setOption('enabled', FALSE); + $view->getExecutable()->displayHandlers->get($display_id)->setOption('enabled', FALSE); $view->save(); - $enabled = Views::executableFactory()->get($view)->displayHandlers->get($display_id)->isEnabled(); + $enabled = $view->getExecutable()->displayHandlers->get($display_id)->isEnabled(); $this->assertFalse($enabled, 'Display ' . $display_id . ' is now disabled'); } diff --git a/core/modules/views/src/Tests/Plugin/DisplayFeedTest.php b/core/modules/views/src/Tests/Plugin/DisplayFeedTest.php index 6aef36f..512541e 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayFeedTest.php +++ b/core/modules/views/src/Tests/Plugin/DisplayFeedTest.php @@ -65,7 +65,7 @@ public function testFeedOutput() { $this->assertEqual($result[0], 'test_display_feed', 'The display title is used for the feed title.'); // Add a block display and attach the feed. - Views::executableFactory()->get($view)->newDisplay('block', NULL, 'test'); + $view->getExecutable()->newDisplay('block', NULL, 'test'); $display = &$view->getDisplay('feed_1'); $display['display_options']['displays']['test'] = 'test'; $view->save(); diff --git a/core/modules/views/src/Tests/Plugin/DisplayTest.php b/core/modules/views/src/Tests/Plugin/DisplayTest.php index c7ac707..81bb1c2 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayTest.php +++ b/core/modules/views/src/Tests/Plugin/DisplayTest.php @@ -225,7 +225,7 @@ public function testReadMore() { $this->assertTrue(empty($result), 'The more link is not shown when view has more records.'); // Test the default value of use_more_always. - $view = Views::executableFactory()->get(entity_create('view')); + $view = entity_create('view')->getExecutable(); $this->assertTrue($view->getDisplay()->getOption('use_more_always'), 'Always display the more link by default.'); } diff --git a/core/modules/views/src/Tests/RenderCacheIntegrationTest.php b/core/modules/views/src/Tests/RenderCacheIntegrationTest.php index 60486c6..183e395 100644 --- a/core/modules/views/src/Tests/RenderCacheIntegrationTest.php +++ b/core/modules/views/src/Tests/RenderCacheIntegrationTest.php @@ -209,7 +209,7 @@ public function testBuildRenderableWithCacheContexts() { $view = View::load('test_view'); $display =& $view->getDisplay('default'); $display['cache_metadata']['contexts'] = ['beatles']; - $executable = Views::executableFactory()->get($view); + $executable = $view->getExecutable(); $build = $executable->buildRenderable(); $this->assertEqual(['beatles'], $build['#cache']['contexts']); diff --git a/core/modules/views/src/Tests/ViewExecutableTest.php b/core/modules/views/src/Tests/ViewExecutableTest.php index 6d04131..3771c0d 100644 --- a/core/modules/views/src/Tests/ViewExecutableTest.php +++ b/core/modules/views/src/Tests/ViewExecutableTest.php @@ -256,7 +256,7 @@ public function testDisplays() { // Test the newDisplay() method. $view = $this->container->get('entity.manager')->getStorage('view')->create(array('id' => 'test_executable_displays')); - $executable = Views::executableFactory()->get($view); + $executable = $view->getExecutable(); $executable->newDisplay('page'); $executable->newDisplay('page'); @@ -442,7 +442,7 @@ public function testValidate() { */ public function testValidateNestedLoops() { $view = View::create(['id' => 'test_validate_nested_loops']); - $executable = Views::executableFactory()->get($view); + $executable = $view->getExecutable(); $executable->newDisplay('display_test'); $executable->newDisplay('display_test'); diff --git a/core/modules/views/src/Tests/ViewStorageTest.php b/core/modules/views/src/Tests/ViewStorageTest.php index b4f2c8c..f30c1dd 100644 --- a/core/modules/views/src/Tests/ViewStorageTest.php +++ b/core/modules/views/src/Tests/ViewStorageTest.php @@ -168,7 +168,7 @@ protected function displayTests() { // Ensure the right display_plugin is created/instantiated. $this->assertEqual($display[$new_id]['display_plugin'], 'page', 'New page display "test" uses the right display plugin.'); - $executable = Views::executableFactory()->get($view); + $executable = $view->getExecutable(); $executable->initDisplay(); $this->assertTrue($executable->displayHandlers->get($new_id) instanceof Page, 'New page display "test" uses the right display plugin.'); @@ -267,7 +267,7 @@ protected function displayMethodTests() { // Tests item related methods(). $view = $this->controller->create(array('base_table' => 'views_test_data')); $view->addDisplay('default'); - $view = Views::executableFactory()->get($view); + $view = $view->getExecutable(); $display_id = 'default'; $expected_items = array(); diff --git a/core/modules/views/src/ViewExecutable.php b/core/modules/views/src/ViewExecutable.php index 03c1555..fe65fe3 100644 --- a/core/modules/views/src/ViewExecutable.php +++ b/core/modules/views/src/ViewExecutable.php @@ -1900,8 +1900,7 @@ public function getUser() { * data, ID, and UUID. */ public function createDuplicate() { - $view = $this->storage->createDuplicate(); - return Views::executableFactory()->get($view); + return $this->storage->createDuplicate()->getExecutable(); } /** diff --git a/core/modules/views/src/Views.php b/core/modules/views/src/Views.php index 841ecdf..747f2f8 100644 --- a/core/modules/views/src/Views.php +++ b/core/modules/views/src/Views.php @@ -227,7 +227,7 @@ public static function getApplicableViews($type) { $result = array(); foreach (\Drupal::entityManager()->getStorage('view')->loadMultiple($entity_ids) as $view) { // Check each display to see if it meets the criteria and is enabled. - $executable = Views::executableFactory()->get($view); + $executable = $view->getExecutable(); $executable->initDisplay(); foreach ($executable->displayHandlers as $id => $handler) { if (!empty($handler->definition[$type]) && $handler->isEnabled()) { diff --git a/core/modules/views/views.services.yml b/core/modules/views/views.services.yml index 1a01543..6ef31b5 100644 --- a/core/modules/views/views.services.yml +++ b/core/modules/views/views.services.yml @@ -4,10 +4,10 @@ services: arguments: [access, '@container.namespaces', '@cache.discovery', '@module_handler'] plugin.manager.views.area: class: Drupal\views\Plugin\ViewsHandlerManager - arguments: [area, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler'] + arguments: [area, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler', '@views.executable'] plugin.manager.views.argument: class: Drupal\views\Plugin\ViewsHandlerManager - arguments: [argument, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler'] + arguments: [argument, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler', '@views.executable'] plugin.manager.views.argument_default: class: Drupal\views\Plugin\ViewsPluginManager arguments: [argument_default, '@container.namespaces', '@cache.discovery', '@module_handler'] @@ -28,13 +28,13 @@ services: arguments: [exposed_form, '@container.namespaces', '@cache.discovery', '@module_handler'] plugin.manager.views.field: class: Drupal\views\Plugin\ViewsHandlerManager - arguments: [field, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler'] + arguments: [field, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler', '@views.executable'] plugin.manager.views.filter: class: Drupal\views\Plugin\ViewsHandlerManager - arguments: [filter, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler'] + arguments: [filter, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler', '@views.executable'] plugin.manager.views.join: class: Drupal\views\Plugin\ViewsHandlerManager - arguments: [join, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler'] + arguments: [join, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler', '@views.executable'] plugin.manager.views.pager: class: Drupal\views\Plugin\ViewsPluginManager arguments: [pager, '@container.namespaces', '@cache.discovery', '@module_handler'] @@ -43,13 +43,13 @@ services: arguments: [query, '@container.namespaces', '@cache.discovery', '@module_handler'] plugin.manager.views.relationship: class: Drupal\views\Plugin\ViewsHandlerManager - arguments: [relationship, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler'] + arguments: [relationship, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler', '@views.executable'] plugin.manager.views.row: class: Drupal\views\Plugin\ViewsPluginManager arguments: [row, '@container.namespaces', '@cache.discovery', '@module_handler'] plugin.manager.views.sort: class: Drupal\views\Plugin\ViewsHandlerManager - arguments: [sort, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler'] + arguments: [sort, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler', '@views.executable'] plugin.manager.views.style: class: Drupal\views\Plugin\ViewsPluginManager arguments: [style, '@container.namespaces', '@cache.discovery', '@module_handler'] @@ -70,7 +70,7 @@ services: arguments: ['@module_handler'] views.route_subscriber: class: Drupal\views\EventSubscriber\RouteSubscriber - arguments: ['@entity.manager', '@state'] + arguments: ['@entity.manager', '@state', '@views.executable'] tags: - { name: 'event_subscriber' } views.exposed_form_cache: diff --git a/core/modules/views_ui/admin.inc b/core/modules/views_ui/admin.inc index c3980f4..64b9077 100644 --- a/core/modules/views_ui/admin.inc +++ b/core/modules/views_ui/admin.inc @@ -216,7 +216,7 @@ function views_ui_nojs_submit($form, FormStateInterface $form_state) { function views_ui_standard_display_dropdown(&$form, FormStateInterface $form_state, $section) { $view = $form_state->get('view'); $display_id = $form_state->get('display_id'); - $executable = Views::executableFactory()->get($view); + $executable = $view->getExecutable(); $displays = $executable->displayHandlers; $current_display = $executable->display_handler; diff --git a/core/modules/views_ui/src/Controller/ViewsUIController.php b/core/modules/views_ui/src/Controller/ViewsUIController.php index 2cfa6ad..77ddb1f 100644 --- a/core/modules/views_ui/src/Controller/ViewsUIController.php +++ b/core/modules/views_ui/src/Controller/ViewsUIController.php @@ -12,6 +12,7 @@ use Drupal\Core\Url; use Drupal\views\ViewExecutable; use Drupal\views\ViewEntityInterface; +use Drupal\views\ViewExecutableFactory; use Drupal\views\Views; use Drupal\views_ui\ViewUI; use Drupal\views\ViewsData; @@ -34,13 +35,23 @@ class ViewsUIController extends ControllerBase { protected $viewsData; /** + * The factory to load a view executable with. + * + * @var \Drupal\views\ViewExecutableFactory + */ + protected $executableFactory; + + /** * Constructs a new \Drupal\views_ui\Controller\ViewsUIController object. * * @param \Drupal\views\ViewsData views_data * The Views data cache object. + * @param \Drupal\views\ViewExecutableFactory $executable_factory + * The factory to load a view executable with. */ - public function __construct(ViewsData $views_data) { + public function __construct(ViewsData $views_data, ViewExecutableFactory $executable_factory) { $this->viewsData = $views_data; + $this->executableFactory = $executable_factory; } /** @@ -48,7 +59,8 @@ public function __construct(ViewsData $views_data) { */ public static function create(ContainerInterface $container) { return new static( - $container->get('views.views_data') + $container->get('views.views_data'), + $container->get('views.executable') ); } @@ -66,7 +78,7 @@ public function reportFields() { $fields = array(); $handler_types = ViewExecutable::getHandlerTypes(); foreach ($views as $view) { - $executable = Views::executableFactory()->get($view); + $executable = $this->executableFactory->get($view); $executable->initDisplay(); foreach ($executable->displayHandlers as $display_id => $display) { if ($executable->setDisplay($display_id)) { diff --git a/core/modules/views_ui/src/Form/Ajax/AddHandler.php b/core/modules/views_ui/src/Form/Ajax/AddHandler.php index 266fc92..da54d50 100644 --- a/core/modules/views_ui/src/Form/Ajax/AddHandler.php +++ b/core/modules/views_ui/src/Form/Ajax/AddHandler.php @@ -61,7 +61,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ), ); - $executable = Views::executableFactory()->get($view); + $executable = $view->getExecutable(); if (!$executable->setDisplay($display_id)) { $form['markup'] = array('#markup' => $this->t('Invalid display id @display', array('@display' => $display_id))); return $form; diff --git a/core/modules/views_ui/src/Form/Ajax/Analyze.php b/core/modules/views_ui/src/Form/Ajax/Analyze.php index 0dc68d8..95e126a 100644 --- a/core/modules/views_ui/src/Form/Ajax/Analyze.php +++ b/core/modules/views_ui/src/Form/Ajax/Analyze.php @@ -41,7 +41,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['#section'] = 'analyze'; $analyzer = Views::analyzer(); - $messages = $analyzer->getMessages(Views::executableFactory()->get($view)); + $messages = $analyzer->getMessages($view->getExecutable()); $form['analysis'] = array( '#prefix' => '