From 2ee77e43159be6e44bc8bcb0e2a0098cf9589e17 Mon Sep 17 00:00:00 2001 From: webchick Date: Fri, 1 Feb 2013 18:20:38 -0800 Subject: [PATCH] Issue #1898926 by damiankloip: Allow ViewExecutable to be pluggable. --- .../Drupal/views/Plugin/Core/Entity/View.php | 2 +- .../Drupal/views/Tests/DefaultViewsTest.php | 2 +- .../views/Tests/Handler/HandlerAllTest.php | 2 +- .../Drupal/views/Tests/ViewExecutableTest.php | 11 +++++++ .../Drupal/views/ViewExecutableFactory.php | 30 +++++++++++++++++++ .../views/lib/Drupal/views/ViewsBundle.php | 2 ++ 6 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 core/modules/views/lib/Drupal/views/ViewExecutableFactory.php diff --git a/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php b/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php index bf7eca21e4c..ed0681e1809 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php +++ b/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php @@ -139,7 +139,7 @@ class View extends ConfigEntityBase implements ViewStorageInterface { public function get($property_name, $langcode = NULL) { // Ensure that an executable View is available. if ($property_name == 'executable' && !isset($this->{$property_name})) { - $this->set('executable', new ViewExecutable($this)); + $this->set('executable', drupal_container()->get('views.executable')->get($this)); } return parent::get($property_name, $langcode); diff --git a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php index a075b6a3dfb..7e8fc93ef04 100644 --- a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php @@ -123,7 +123,7 @@ class DefaultViewsTest extends WebTestBase { $views = $controller->load(); foreach ($views as $name => $view_storage) { - $view = new ViewExecutable($view_storage); + $view = $view_storage->get('executable'); $view->initDisplay(); foreach ($view->storage->get('display') as $display_id => $display) { $view->setDisplay($display_id); diff --git a/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerAllTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerAllTest.php index 1043b641d5a..dca0da1cf33 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerAllTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerAllTest.php @@ -60,7 +60,7 @@ class HandlerAllTest extends HandlerTestBase { } $view = entity_create('view', array('base_table' => $base_table)); - $view = new ViewExecutable($view); + $view = $view->get('executable'); // @todo The groupwise relationship is currently broken. $exclude[] = 'taxonomy_term_data:tid_representative'; diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php index b5c67116d43..8f849417dc4 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php @@ -9,6 +9,7 @@ namespace Drupal\views\Tests; use Symfony\Component\HttpFoundation\Response; use Drupal\views\ViewExecutable; +use Drupal\views\ViewExecutableFactory; use Drupal\views\DisplayBag; use Drupal\views\Plugin\views\display\DefaultDisplay; use Drupal\views\Plugin\views\display\Page; @@ -81,6 +82,16 @@ class ViewExecutableTest extends ViewUnitTestBase { $this->enableModules(array('system', 'node', 'comment', 'user', 'filter')); } + /** + * Tests the views.exectuable container service. + */ + public function testFactoryService() { + $factory = $this->container->get('views.executable'); + $this->assertTrue($factory instanceof ViewExecutableFactory, 'A ViewExecutableFactory instance was returned from the container.'); + $view = entity_load('view', 'test_executable_displays'); + $this->assertTrue($factory->get($view) instanceof ViewExecutable, 'A ViewExecutable instance was returned from the factory.'); + } + /** * Tests the initDisplay() and initHandlers() methods. */ diff --git a/core/modules/views/lib/Drupal/views/ViewExecutableFactory.php b/core/modules/views/lib/Drupal/views/ViewExecutableFactory.php new file mode 100644 index 00000000000..59a052afb8c --- /dev/null +++ b/core/modules/views/lib/Drupal/views/ViewExecutableFactory.php @@ -0,0 +1,30 @@ +register('views.views_data', 'Drupal\views\ViewsDataCache') ->addArgument(new Reference('cache.views_info')) ->addArgument(new Reference('config.factory')); + + $container->register('views.executable', 'Drupal\views\ViewExecutableFactory'); } }