Commit 2ee77e43 authored by webchick's avatar webchick

Issue #1898926 by damiankloip: Allow ViewExecutable to be pluggable.

parent 530c4c45
......@@ -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);
......
......@@ -123,7 +123,7 @@ public function testDefaultViews() {
$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);
......
......@@ -60,7 +60,7 @@ public function testHandlers() {
}
$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';
......
......@@ -9,6 +9,7 @@
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 @@ protected function setUp() {
$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.
*/
......
<?php
/**
* @file
* Contains \Drupal\views\ViewExecutableFactory.
*/
namespace Drupal\views;
use Drupal\views\Plugin\Core\Entity\View;
/**
* Defines the cache backend factory.
*/
class ViewExecutableFactory {
/**
* Instantiates a ViewExecutable class.
*
* @param \Drupal\views\Plugin\Core\Entity\View $view
* A view entity instance.
*
* @return \Drupal\views\ViewExecutable
* A ViewExecutable instance.
*/
public static function get(View $view) {
return new ViewExecutable($view);
}
}
......@@ -35,6 +35,8 @@ public function build(ContainerBuilder $container) {
$container->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');
}
}
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