Commit ad514aea authored by dawehner's avatar dawehner Committed by tim.plunkett

Issue #1751358 by dawehner: Split up View class into ViewStorage and ViewExecutable.

parent 09a8340d
......@@ -7,7 +7,7 @@
use Drupal\Core\Database\Database;
use Drupal\views\TempStore\UserTempStore;
use Drupal\views\View;
use Drupal\views\ViewExecutable;
use Drupal\views\Analyzer;
use Drupal\views\Plugin\views\wizard\WizardException;
......@@ -2001,7 +2001,7 @@ function views_ui_import_validate($form, &$form_state) {
}
}
foreach (View::viewsHandlerTypes() as $type => $info) {
foreach (ViewExecutable::viewsHandlerTypes() as $type => $info) {
$handlers = $display->handler->getHandlers($type);
if ($handlers) {
foreach ($handlers as $id => $handler) {
......@@ -2129,7 +2129,7 @@ function views_ui_edit_form_get_bucket($type, $view, $display) {
$build = array(
'#theme_wrappers' => array('views_ui_display_tab_bucket'),
);
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
$build['#overridden'] = FALSE;
$build['#defaulted'] = FALSE;
......@@ -3247,7 +3247,7 @@ function views_ui_config_type_form($form, &$form_state) {
$display_id = $form_state['display_id'];
$type = $form_state['type'];
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
if (!$view->setDisplay($display_id)) {
views_ajax_error(t('Invalid display id @display', array('@display' => $display_id)));
}
......@@ -3279,7 +3279,7 @@ function views_ui_config_type_form($form, &$form_state) {
* Submit handler for type configuration form
*/
function views_ui_config_type_form_submit($form, &$form_state) {
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
$display = &$form_state['view']->display[$form_state['display_id']];
// Store in cache
......@@ -3294,7 +3294,7 @@ function views_ui_rearrange_form($form, &$form_state) {
$display_id = $form_state['display_id'];
$type = $form_state['type'];
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
if (!$view->setDisplay($display_id)) {
views_ajax_error(t('Invalid display id @display', array('@display' => $display_id)));
}
......@@ -3519,7 +3519,7 @@ function theme_views_ui_build_group_filter_form($variables) {
* Submit handler for rearranging form.
*/
function views_ui_rearrange_form_submit($form, &$form_state) {
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
$display = &$form_state['view']->display[$form_state['display_id']];
$old_fields = $display->handler->getOption($types[$form_state['type']]['plural']);
......@@ -3555,7 +3555,7 @@ function views_ui_rearrange_filter_form($form, &$form_state) {
$display_id = $form_state['display_id'];
$type = $form_state['type'];
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
if (!$view->setDisplay($display_id)) {
views_ajax_render(t('Invalid display id @display', array('@display' => $display_id)));
}
......@@ -3821,7 +3821,7 @@ function theme_views_ui_rearrange_filter_form(&$vars) {
* Submit handler for rearranging form
*/
function views_ui_rearrange_filter_form_submit($form, &$form_state) {
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
$display = &$form_state['view']->display[$form_state['display_id']];
$remember_groups = array();
......@@ -3944,7 +3944,7 @@ function views_ui_add_item_form($form, &$form_state) {
}
$display = &$view->display[$display_id];
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
$ltitle = $types[$type]['ltitle'];
$section = $types[$type]['plural'];
......@@ -4060,7 +4060,7 @@ function views_ui_add_item_form($form, &$form_state) {
*/
function views_ui_add_item_form_submit($form, &$form_state) {
$type = $form_state['type'];
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
$section = $types[$type]['plural'];
// Handle the override select.
......@@ -4187,7 +4187,7 @@ function views_ui_config_item_form($form, &$form_state) {
$form['markup'] = array('#markup' => t("Error: handler for @table > @field doesn't exist!", array('@table' => $item['table'], '@field' => $item['field'])));
}
else {
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
// If this item can come from the default display, show a dropdown
// that lets the user choose which display the changes should apply to.
......@@ -4307,7 +4307,7 @@ function views_ui_config_item_form_submit_temporary($form, &$form_state) {
// Run it through the handler's submit function.
$form_state['handler']->submitOptionsForm($form['options'], $form_state);
$item = $form_state['handler']->options;
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
// For footer/header $handler_type is area but $type is footer/header.
// For all other handle types it's the same.
......@@ -4361,7 +4361,7 @@ function views_ui_config_item_form_submit($form, &$form_state) {
// Run it through the handler's submit function.
$form_state['handler']->submitOptionsForm($form['options'], $form_state);
$item = $form_state['handler']->options;
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
// For footer/header $handler_type is area but $type is footer/header.
// For all other handle types it's the same.
......@@ -4437,7 +4437,7 @@ function views_ui_config_item_group_form($type, &$form_state) {
}
else {
$handler->init($view, $item);
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
$form['#title'] = t('Configure group settings for @type %item', array('@type' => $types[$type]['lstitle'], '%item' => $handler->adminLabel()));
......@@ -4538,7 +4538,7 @@ function views_ui_config_item_extra_form($form, &$form_state) {
}
else {
$handler->init($view, $item);
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
$form['#title'] = t('Configure extra settings for @type %item', array('@type' => $types[$type]['lstitle'], '%item' => $handler->adminLabel()));
......@@ -4609,7 +4609,7 @@ function views_ui_config_style_form($form, &$form_state) {
}
else {
$handler->init($view, $item);
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
$form['#title'] = t('Configure summary style for @type %item', array('@type' => $types[$type]['lstitle'], '%item' => $handler->adminLabel()));
......@@ -5321,7 +5321,7 @@ function views_ui_field_list() {
foreach ($views as $view) {
foreach ($view->display as $display_id => $display) {
if ($view->setDisplay($display_id)) {
foreach (View::viewsHandlerTypes() as $type => $info) {
foreach (ViewExecutable::viewsHandlerTypes() as $type => $info) {
foreach ($view->getItems($type, $display_id) as $item) {
$data = views_fetch_data($item['table']);
if (isset($data[$item['field']]) && isset($data[$item['field']][$type])
......
......@@ -7,7 +7,7 @@
namespace Drupal\views;
use Drupal\views\View;
use Drupal\views\ViewExecutable;
/**
* This tool is a small plugin manager to perform analysis on a view and
......@@ -22,14 +22,14 @@ class Analyzer {
/**
* The view to analyze.
*
* @var Drupal\views\View.
* @var Drupal\views\ViewExecutable.
*/
protected $view;
/**
* Constructs the analyzer object.
*
* @param Drupal\views\View $view
* @param Drupal\views\ViewExecutable $view
* (optional) The view to analyze.
*/
function __construct(View $view = NULL) {
......@@ -41,7 +41,7 @@ function __construct(View $view = NULL) {
/**
* Sets the view which is analyzed by this analyzer.
*
* @param Drupal\views\View
* @param Drupal\views\ViewExecutable
* The view to analyze.
*/
public function setView(View $view = NULL) {
......
......@@ -9,7 +9,7 @@
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\views\Plugin\views\PluginBase;
use Drupal\views\View;
use Drupal\views\ViewExecutable;
abstract class HandlerBase extends PluginBase {
......@@ -81,7 +81,7 @@ public function __construct(array $configuration, $plugin_id, DiscoveryInterface
/**
* Init the handler with necessary data.
*
* @param Drupal\views\View $view
* @param Drupal\views\ViewExecutable $view
* The $view object this handler is attached to.
* @param array $options
* The item from the database; the actual contents of this will vary
......@@ -104,7 +104,7 @@ public function init(&$view, &$options) {
$options['field'] = $this->actualField;
}
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
$plural = $this->definition['plugin_type'];
if (isset($types[$plural]['plural'])) {
$plural = $types[$plural]['plural'];
......@@ -317,7 +317,7 @@ public function usesGroupBy() {
public function buildGroupByForm(&$form, &$form_state) {
$view = &$form_state['view'];
$display_id = $form_state['display_id'];
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
$type = $form_state['type'];
$id = $form_state['id'];
......
......@@ -22,7 +22,7 @@ abstract class PluginBase extends ComponentPluginBase {
/**
* The top object of a view.
*
* @var Drupal\views\View
* @var Drupal\views\ViewExecutable
*/
public $view = NULL;
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Plugin\views\display;
use Drupal\views\View;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\PluginBase;
/**
......@@ -32,7 +32,7 @@ abstract class DisplayPluginBase extends PluginBase {
/**
* The top object of a view.
*
* @var Drupal\views\View
* @var Drupal\views\ViewExecutable
*/
var $view = NULL;
......@@ -840,7 +840,7 @@ public function &getHandler($type, $id) {
public function getHandlers($type) {
if (!isset($this->handlers[$type])) {
$this->handlers[$type] = array();
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
$plural = $types[$type]['plural'];
foreach ($this->getOption($plural) as $id => $info) {
......@@ -2639,7 +2639,7 @@ public function validate() {
}
// Validate handlers
foreach (View::viewsHandlerTypes() as $type => $info) {
foreach (ViewExecutable::viewsHandlerTypes() as $type => $info) {
foreach ($this->getHandlers($type) as $handler) {
$result = $handler->validate();
if (!empty($result) && is_array($result)) {
......@@ -2664,7 +2664,7 @@ public function validate() {
*
*/
public function isIdentifierUnique($id, $identifier) {
foreach (View::viewsHandlerTypes() as $type => $info) {
foreach (ViewExecutable::viewsHandlerTypes() as $type => $info) {
foreach ($this->getHandlers($type) as $key => $handler) {
if ($handler->canExpose() && $handler->isExposed()) {
if ($handler->isAGroup()) {
......
......@@ -8,7 +8,7 @@
namespace Drupal\views\Plugin\views\relationship;
use Drupal\Core\Database\Query\AlterableInterface;
use Drupal\views\View;
use Drupal\views\ViewExecutable;
use Drupal\Core\Annotation\Plugin;
/**
......
......@@ -50,7 +50,7 @@ public function validateView(array $form, array &$form_state);
* @param array $form_state
* The current state of the wizard form.
*
* @return Drupal\views\View
* @return Drupal\views\ViewExecutable
* The created view object.
*
* @throws Drupal\views\Plugin\views\wizard\WizardException
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Plugin\views\wizard;
use Drupal\views\View;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\PluginBase;
use Drupal\views\Plugin\views\wizard\WizardInterface;
......@@ -542,7 +542,7 @@ protected function build_sorts(&$form, &$form_state) {
/**
* Instantiates a view object from form values.
*
* @return
* @return Drupal\views\ViewExecutable
* The instantiated view object.
*/
protected function instantiate_view($form, &$form_state) {
......@@ -565,7 +565,9 @@ protected function instantiate_view($form, &$form_state) {
$this->addDisplays($view, $display_options, $form, $form_state);
return $view;
$executable = new ViewExecutable($view);
return $executable;
}
/**
......@@ -1035,7 +1037,7 @@ protected function set_override_options(array $options, DisplayPluginBase $displ
* @param bool $unset
* Should the view be removed from the list of validated views.
*
* @return Drupal\views\View $view
* @return Drupal\views\ViewExecutable $view
* The validated view object.
*/
protected function retrieve_validated_view(array $form, array &$form_state, $unset = TRUE) {
......@@ -1056,7 +1058,7 @@ protected function retrieve_validated_view(array $form, array &$form_state, $uns
* The full wizard form array.
* @param array $form_state
* The current state of the wizard form.
* @param Drupal\views\View $view
* @param Drupal\views\ViewExecutable $view
* The validated view object.
*/
protected function set_validated_view(array $form, array &$form_state, View $view) {
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Plugin;
use Drupal\views\View;
use Drupal\views\ViewExecutable;
/**
* Basic test for pluggable caching.
......@@ -33,7 +33,7 @@ protected function setUp() {
/**
* Build and return a basic view of the views_test_data table.
*
* @return Drupal\views\View
* @return Drupal\views\ViewExecutable
*/
protected function getBasicView() {
// Create the basic view.
......
......@@ -44,7 +44,7 @@ public function testMappedOutput() {
/**
* Tests the mapping of fields.
*
* @param Drupal\views\View $view
* @param Drupal\views\ViewExecutable $view
* The view to test.
*
* @return string
......
<?php
/**
* Definition of Drupal\views\Tests\ViewExecutable.
*/
namespace Drupal\views\Tests;
/**
* Tests the ViewExecutable class.
*
* @see Drupal\views\ViewExecutableExecutable
*/
class ViewExecutableTest extends ViewTestBase {
/**
* Properties that should be stored in the configuration.
*
* @var array
*/
protected $configProperties = array(
'disabled',
'api_version',
'name',
'description',
'tag',
'base_table',
'human_name',
'core',
'display',
);
/**
* Properties that should be stored in the executable.
*
* @var array
*/
protected $executableProperties = array(
'build_info'
);
public static function getInfo() {
return array(
'name' => 'View executable tests',
'description' => 'Tests the ViewExecutable class.',
'group' => 'Views'
);
}
/**
* Tests the generation of the executable object.
*/
public function testConstructing() {
$view = $this->getView();
}
/**
* Tests the accessing of values on the object.
*/
public function testProperties() {
$view = $this->getView();
$storage = $view->storage;
foreach ($this->configProperties as $property) {
$this->assertTrue(isset($view->{$property}));
$this->assertIdentical($view->{$property}, $storage->{$storage});
}
foreach ($this->executableProperties as $property) {
$this->assertTrue(isset($view->{$property}));
}
// Set one storage property manually on the storage and verify that it is
// access on the executable.
$storage->human_name = $this->randomName();
$this->assertIdentical($view->human_name, $storage->human_name);
}
}
......@@ -9,7 +9,7 @@
use Drupal\simpletest\WebTestBase;
use Drupal\views\ViewStorageController;
use Drupal\views\View;
use Drupal\views\ViewExecutable;
use Drupal\views\ViewDisplay;
use Drupal\views\Plugin\views\display\Page;
......@@ -91,12 +91,13 @@ function testConfigurationEntityCRUD() {
* Tests loading configuration entities.
*/
protected function loadTests() {
$view = $this->loadView('archive');
$storage = $this->loadView('archive');
$view = new ViewExecutable();
$data = config('views.view.archive')->get();
// Confirm that an actual view object is loaded and that it returns all of
// expected properties.
$this->assertTrue($view instanceof View, 'Single View instance loaded.');
$this->assertTrue($view instanceof ViewStorage, 'Single View instance loaded.');
foreach ($this->config_properties as $property) {
$this->assertTrue(isset($view->{$property}), format_string('Property: @property loaded onto View.', array('@property' => $property)));
}
......@@ -293,7 +294,7 @@ protected function statusTests() {
* @param string $view_name
* The machine name of the view.
*
* @return object Drupal\views\View.
* @return object Drupal\views\ViewExecutable.
* The loaded view object.
*/
protected function loadView($view_name) {
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests;
use Drupal\views\View;
use Drupal\views\ViewExecutable;
/**
* Views class tests.
......@@ -71,10 +71,10 @@ function assertViewDestroy($view) {
}
/**
* Tests view::viewsHandlerTypes().
* Tests ViewExecutable::viewsHandlerTypes().
*/
public function testViewshandlerTypes() {
$types = View::viewsHandlerTypes();
$types = ViewExecutable::viewsHandlerTypes();
foreach (array('field', 'filter', 'argument', 'sort', 'header', 'footer', 'empty') as $type) {
$this->assertTrue(isset($types[$type]));
// @todo The key on the display should be footers, headers and empties
......
......@@ -22,7 +22,7 @@ abstract class ViewTestBase extends WebTestBase {
/**
* The view to use for the test.
*
* @var Drupal\views\View
* @var Drupal\views\ViewExecutable
*/
protected $view;
......@@ -390,7 +390,7 @@ protected function dataSet() {
/**
* Build and return a basic view of the views_test_data table.
*
* @return Drupal\views\View
* @return Drupal\views\ViewExecutable
*/
protected function getBasicView() {
return $this->createViewFromConfig('test_view');
......@@ -402,7 +402,7 @@ protected function getBasicView() {
* @param string $view_name
* The name of the test view to create.
*
* @return Drupal\views\View
* @return Drupal\views\ViewExecutable
* A View instance.
*/
protected function createViewFromConfig($view_name) {
......@@ -421,11 +421,11 @@ protected function createViewFromConfig($view_name) {
/**
* Clones the view used in this test and sets the default display.
*
* @param Drupal\views\View $original_view
* @param Drupal\views\ViewStorage $original_view
* (optional) The view to clone. If not specified, the default view for the
* test will be used.
*
* @return Drupal\views\View
* @return Drupal\views\ViewStorage
* A clone of the view.
*/
protected function getView($original_view = NULL) {
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\views\View.
* Definition of Drupal\views\ViewExecutable.
*/
namespace Drupal\views;
......@@ -20,78 +20,13 @@
* An object to contain all of the data to generate a view, plus the member
* functions to build the view query, execute the query and render the output.
*/
class View extends ViewStorage {
/**
* The name of the base table this view will use.
*
* @var string
*/
public $base_table = 'node';
/**
* The name of the base field to use.
*
* @var string
*/
public $base_field = 'nid';
/**
* The name of the view.
*
* @var string
*/
public $name = '';
/**
* The description of the view, which is used only in the interface.
*
* @var string
*/
public $description = '';
/**
* The "tags" of a view.
*
* The tags are stored as a single string, though it is used as multiple tags
* for example in the views overview.
*
* @var string
*/
public $tag = '';
/**
* The human readable name of the view.
*
* @var string
*/
public $human_name = '';
/**
* The core version the view was created for.
*
* @var int
*/
public $core = DRUPAL_CORE_COMPATIBILITY;
/**
* The views API version this view was created by.
*
* @var string
*/
public $api_version = VIEWS_API_VERSION;
class ViewExecutable {
/**
* Returns whether the view's status is disabled or not.
* The config entity in which the view is stored.
*
* This value is used for exported view, to provide some default views which
* aren't enabled.
*
* @var bool
* @var Drupal\views\ViewStorage
*/
public $disabled = FALSE;
// State variables
protected $storage;
/**
* Whether or not the view has been built.
......@@ -266,16 +201,6 @@ class View extends ViewStorage {
*/
public $display_handler;
/**
* Stores all display handlers of this view.
*
* An array containing Drupal\views\Plugin\views\display\DisplayPluginBase
* objects.
*
* @var array
*/
public $display;
/**
* The current used style plugin.
*
......@@ -404,6 +329,45 @@ class View extends ViewStorage {
*/
protected $response = NULL;
/**
* Constructs a new ViewExecutable object.
*
* @param Drupal\views\ViewStorage $storage
* The view config entity the actual information is stored on.
*/
function __construct(ViewStorage $storage) {
// Reference the storage and the executable to each other.
$this->storage = $storage;
$this->storage->setExecutable($this);
}
/**
* @todo
*/
function __get($name) {
if (property_exists($this->storage, $name)) {
return $this->storage->{$name};
}
}
/**
* @todo
*/
function __set($name, $value) {
if (property_exists($this->storage, $name)) {
$this->storage->{$name} = $value;
}
}
/**
* @todo
*/
function __call($name, $arguments) {
if (method_exists($this->storage, $name)) {
call_user_func_array(array($this->storage, $name), $arguments);
}
}
/**
* Perform automatic updates when loading or importing a view.
*
......@@ -712,7 +676,7 @@ public function initStyle() {
*/
public function initHandlers() {
if (empty($this->inited)) {
foreach (View::viewsHandlerTypes() as $key => $info) {
foreach (ViewExecutable::viewsHandlerTypes() as $key => $info) {
$this->_initHandler($key, $info);
}
$this->inited = TRUE;
......@@ -776,7 +740,7 @@ public function getBaseTables() {
* Run the preQuery() on all active handlers.
*/
protected function _preQuery() {
foreach (View::viewsHandlerTypes() as $key => $info) {
foreach (ViewExecutable::viewsHandlerTypes() as $key => $info) {
$handlers = &$this->$key;
$position = 0;
foreach ($handlers as $id => $handler) {
......@@ -791,7 +755,7 @@ protected function _preQuery() {
* Run the postExecute() on all active handlers.
*/
protected function _postExecute() {
foreach (View::viewsHandlerTypes() as $key => $info) {
foreach (ViewExecutable::viewsHandlerTypes() as $key => $info) {
$handlers = &$this->$key;
foreach ($handlers as $id => $handler) {
$handlers[$id]->postExecute($this->result);
......@@ -1616,21 +1580,6 @@ public function setTitle($title) {
return TRUE;
}
/**
* Return the human readable name for a view.
*
* When a certain view doesn't have a human readable name return the machine readable name.
*/
public function getHumanName() {
if (!empty($this->human_name)) {
$human_name = $this->human_name;
}
else {
$human_name = $this->name;
}
return $human_name;
}
/**
* Force the view to build a title.