Commit 91fbd4b5 authored by alexpott's avatar alexpott

Issue #2029733 by damiankloip, tim.plunkett: Add a getExecutable() method to View.

parent 1eb378f4
......@@ -120,15 +120,18 @@ class View extends ConfigEntityBase implements ViewStorageInterface {
protected $module = 'views';
/**
* Overrides Drupal\Core\Entity\EntityInterface::get().
* Gets an executable instance for this view.
*
* @return \Drupal\views\ViewExecutable
* A view executable instance.
*/
public function get($property_name, $langcode = NULL) {
public function getExecutable() {
// Ensure that an executable View is available.
if ($property_name == 'executable' && !isset($this->{$property_name})) {
$this->set('executable', Views::executableFactory()->get($this));
if (!isset($this->executable)) {
$this->executable = Views::executableFactory()->get($this);
}
return parent::get($property_name, $langcode);
return $this->executable;
}
/**
......@@ -274,7 +277,7 @@ public function newDisplay($plugin_id = 'page', $title = NULL, $id = NULL) {
// We can't use get() here as it will create an ViewExecutable instance if
// there is not already one.
if (isset($this->executable)) {
$executable = $this->get('executable');
$executable = $this->getExecutable();
$executable->initDisplay();
$executable->displayHandlers->addInstanceID($id);
return $executable->displayHandlers->get($id);
......
......@@ -83,7 +83,7 @@ public function getDerivativeDefinitions(array $base_plugin_definition) {
if (!$view->status()) {
continue;
}
$executable = $view->get('executable');
$executable = $view->getExecutable();
$executable->initDisplay();
foreach ($executable->displayHandlers as $display) {
// Add a block plugin definition for each block display.
......
......@@ -44,7 +44,7 @@ public function getDerivativeDefinitions(array $base_plugin_definition) {
if (!$view->status()) {
continue;
}
$executable = $view->get('executable');
$executable = $view->getExecutable();
$executable->initDisplay();
foreach ($executable->displayHandlers as $display) {
if (isset($display) && $display->getOption('exposed_block')) {
......
......@@ -847,7 +847,7 @@ public function displayExposedForm($form, &$form_state) {
$this->defaultExposeOptions();
}
$form_state['view']->get('executable')->setItem($form_state['display_id'], $form_state['type'], $form_state['id'], $item);
$form_state['view']->getExecutable()->setItem($form_state['display_id'], $form_state['type'], $form_state['id'], $item);
$form_state['view']->addFormToStack($form_state['form_key'], $form_state['display_id'], $form_state['type'], $form_state['id'], TRUE, TRUE);
......@@ -875,7 +875,7 @@ public function submitTemporaryForm($form, &$form_state) {
}
$override = NULL;
$executable = $form_state['view']->get('executable');
$executable = $form_state['view']->getExecutable();
if ($executable->display_handler->useGroupBy() && !empty($item['group_type'])) {
if (empty($executable->query)) {
$executable->initQuery();
......@@ -900,7 +900,7 @@ public function submitTemporaryForm($form, &$form_state) {
$handler->unpackOptions($handler->options, $options, NULL, FALSE);
// Store the item back on the view.
$executable = $form_state['view']->get('executable');
$executable = $form_state['view']->getExecutable();
$executable->temporary_options[$type][$form_state['id']] = $handler->options;
// @todo Decide if \Drupal\views_ui\Form\Ajax\ViewsFormBase::getForm() is
......
......@@ -426,7 +426,7 @@ public function buildGroupForm($form, &$form_state) {
$this->buildGroupOptions();
}
$form_state['view']->get('executable')->setItem($form_state['display_id'], $form_state['type'], $form_state['id'], $item);
$form_state['view']->getExecutable()->setItem($form_state['display_id'], $form_state['type'], $form_state['id'], $item);
$form_state['view']->addFormToStack($form_state['form_key'], $form_state['display_id'], $form_state['type'], $form_state['id'], TRUE, TRUE);
......@@ -1089,7 +1089,7 @@ public function addGroupForm($form, &$form_state) {
// Add a new row.
$item['group_info']['group_items'][] = array();
$form_state['view']->get('executable')->setItem($form_state['display_id'], $form_state['type'], $form_state['id'], $item);
$form_state['view']->getExecutable()->setItem($form_state['display_id'], $form_state['type'], $form_state['id'], $item);
$form_state['view']->cacheSet();
$form_state['rerender'] = TRUE;
......
......@@ -163,7 +163,7 @@ public function buildOptionsForm(&$form, &$form_state) {
protected function getTemporaryView() {
$view = entity_create('view', array('base_table' => $this->definition['base']));
$view->addDisplay('default');
return $view->get('executable');
return $view->getExecutable();
}
/**
......
......@@ -63,7 +63,7 @@ protected function defineOptions() {
public function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state);
if (isset($this->base_table)) {
$executable = $form_state['view']->get('executable');
$executable = $form_state['view']->getExecutable();
// A whole bunch of code to figure out what relationships are valid for
// this item.
......
......@@ -694,7 +694,7 @@ protected function alterDisplayOptions(&$display_options, $form, $form_state) {
protected function addDisplays(View $view, $display_options, $form, $form_state) {
// Initialize and store the view executable to get the display plugin
// instances.
$executable = $view->get('executable');
$executable = $view->getExecutable();
// Display: Master
$default_display = $view->newDisplay('default', 'Master', 'default');
......@@ -1158,7 +1158,7 @@ protected function setValidatedView(array $form, array &$form_state, ViewUI $vie
*/
public function validateView(array $form, array &$form_state) {
$view = $this->instantiateView($form, $form_state);
$errors = $view->get('executable')->validate();
$errors = $view->getExecutable()->validate();
if (empty($errors)) {
$this->setValidatedView($form, $form_state, $view);
......
......@@ -117,7 +117,7 @@ public function testDefaultViews() {
$views = $controller->loadMultiple();
foreach ($views as $name => $view_storage) {
$view = $view_storage->get('executable');
$view = $view_storage->getExecutable();
$view->initDisplay();
foreach ($view->storage->get('display') as $display_id => $display) {
$view->setDisplay($display_id);
......
......@@ -61,7 +61,7 @@ public function testHandlers() {
}
$view = entity_create('view', array('base_table' => $base_table));
$view = $view->get('executable');
$view = $view->getExecutable();
// @todo The groupwise relationship is currently broken.
$exclude[] = 'taxonomy_term_data:tid_representative';
......
......@@ -201,7 +201,7 @@ public function testLoadFunctions() {
// Test $exclude_view parameter.
$this->assertFalse(array_key_exists('archive', views_get_views_as_options(TRUE, 'all', 'archive')), 'View excluded from options based on name');
$this->assertFalse(array_key_exists('archive:default', views_get_views_as_options(FALSE, 'all', 'archive:default')), 'View display excluded from options based on name');
$this->assertFalse(array_key_exists('archive', views_get_views_as_options(TRUE, 'all', $archive->get('executable'))), 'View excluded from options based on object');
$this->assertFalse(array_key_exists('archive', views_get_views_as_options(TRUE, 'all', $archive->getExecutable())), 'View excluded from options based on object');
// Test the $opt_group parameter.
$expected_opt_groups = array();
......
......@@ -175,7 +175,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 = $view->get('executable');
$executable = $view->getExecutable();
$executable->initDisplay();
$this->assertTrue($executable->displayHandlers->get($new_id) instanceof Page, 'New page display "test" uses the right display plugin.');
......@@ -259,7 +259,7 @@ protected function displayMethodTests() {
$display = $view->newDisplay('feed');
$this->assertEqual($display, 'feed_1');
$executable = $view->get('executable');
$executable = $view->getExecutable();
$executable->initDisplay();
$this->assertTrue($executable->displayHandlers->get('page_1') instanceof Page);
......@@ -272,7 +272,7 @@ protected function displayMethodTests() {
// Tests item related methods().
$view = $this->controller->create(array('base_table' => 'views_test_data'));
$view->addDisplay('default');
$view = $view->get('executable');
$view = $view->getExecutable();
$display_id = 'default';
$expected_items = array();
......
......@@ -1740,7 +1740,7 @@ public function getBreadcrumb($set = FALSE) {
* data, ID, and UUID.
*/
public function createDuplicate() {
return $this->storage->createDuplicate()->get('executable');
return $this->storage->createDuplicate()->getExecutable();
}
/**
......
......@@ -936,7 +936,7 @@ function views_get_applicable_views($type) {
$result = array();
foreach (Drupal::entityManager()->getStorageController('view')->loadMultiple($entity_ids) as $view) {
// Check each display to see if it meets the criteria and is enabled.
$executable = $view->get('executable');
$executable = $view->getExecutable();
$executable->initDisplay();
foreach ($executable->displayHandlers as $id => $handler) {
if (!empty($handler->definition[$type]) && $handler->isEnabled()) {
......
......@@ -344,7 +344,7 @@ function views_ui_pre_render_move_argument_options($form) {
function views_ui_standard_display_dropdown(&$form, &$form_state, $section) {
$view = &$form_state['view'];
$display_id = $form_state['display_id'];
$executable = $view->get('executable');
$executable = $view->getExecutable();
$displays = $executable->displayHandlers;
$current_display = $executable->display_handler;
......
......@@ -89,7 +89,7 @@ public function reportFields() {
$fields = array();
$handler_types = ViewExecutable::viewsHandlerTypes();
foreach ($views as $view) {
$executable = $view->get('executable');
$executable = $view->getExecutable();
$executable->initDisplay();
foreach ($executable->displayHandlers as $display_id => $display) {
if ($executable->setDisplay($display_id)) {
......
......@@ -60,7 +60,7 @@ public function buildForm(array $form, array &$form_state) {
),
);
$executable = $view->get('executable');
$executable = $view->getExecutable();
$executable->setDisplay($display_id);
$display = &$executable->displayHandlers->get($display_id);
......
......@@ -40,7 +40,7 @@ public function buildForm(array $form, array &$form_state) {
$form['#section'] = 'analyze';
$analyzer = Views::analyzer();
$messages = $analyzer->getMessages($view->get('executable'));
$messages = $analyzer->getMessages($view->getExecutable());
$form['analysis'] = array(
'#prefix' => '<div class="form-item">',
......
......@@ -63,7 +63,7 @@ public function buildForm(array $form, array &$form_state) {
'#attributes' => array('class' => array('scroll')),
),
);
$executable = $view->get('executable');
$executable = $view->getExecutable();
$save_ui_cache = FALSE;
$executable->setDisplay($display_id);
$item = $executable->getItem($display_id, $type, $id);
......@@ -210,7 +210,7 @@ public function submitForm(array &$form, array &$form_state) {
}
$override = NULL;
$executable = $form_state['view']->get('executable');
$executable = $form_state['view']->getExecutable();
if ($executable->display_handler->useGroupBy() && !empty($item['group_type'])) {
if (empty($executable->query)) {
$executable->initQuery();
......@@ -252,7 +252,7 @@ public function submitForm(array &$form, array &$form_state) {
public function remove(&$form, &$form_state) {
// Store the item back on the view
list($was_defaulted, $is_defaulted) = $form_state['view']->getOverrideValues($form, $form_state);
$executable = $form_state['view']->get('executable');
$executable = $form_state['view']->getExecutable();
// If the display selection was changed toggle the override value.
if ($was_defaulted != $is_defaulted) {
$display = &$executable->displayHandlers->get($form_state['display_id']);
......
......@@ -62,7 +62,7 @@ public function buildForm(array $form, array &$form_state) {
'#attributes' => array('class' => array('scroll')),
),
);
$executable = $view->get('executable');
$executable = $view->getExecutable();
$executable->setDisplay($display_id);
$item = $executable->getItem($display_id, $type, $id);
......@@ -110,7 +110,7 @@ public function submitForm(array &$form, array &$form_state) {
}
// Store the item back on the view
$form_state['view']->get('executable')->setItem($form_state['display_id'], $form_state['type'], $form_state['id'], $item);
$form_state['view']->getExecutable()->setItem($form_state['display_id'], $form_state['type'], $form_state['id'], $item);
// Write to cache
$form_state['view']->cacheSet();
......
......@@ -63,7 +63,7 @@ public function buildForm(array $form, array &$form_state) {
'#attributes' => array('class' => array('scroll')),
),
);
$executable = $view->get('executable');
$executable = $view->getExecutable();
if (!$executable->setDisplay($display_id)) {
views_ajax_render(t('Invalid display id @display', array('@display' => $display_id)));
}
......@@ -101,7 +101,7 @@ public function submitForm(array &$form, array &$form_state) {
$id = $form_state['id'];
$handler = Views::handlerManager($type)->getHandler($item);
$executable = $form_state['view']->get('executable');
$executable = $form_state['view']->getExecutable();
$handler->init($executable, $executable->display_handler, $item);
$handler->submitGroupByForm($form, $form_state);
......
......@@ -63,7 +63,7 @@ public function buildForm(array $form, array &$form_state) {
$display_id = $form_state['display_id'];
$section = $form_state['section'];
$executable = $view->get('executable');
$executable = $view->getExecutable();
$executable->setDisplay($display_id);
$display = &$executable->display[$display_id];
......@@ -98,7 +98,7 @@ public function buildForm(array $form, array &$form_state) {
* Overrides \Drupal\views_ui\Form\Ajax\ViewsFormBase::validateForm().
*/
public function validateForm(array &$form, array &$form_state) {
$form_state['view']->get('executable')->displayHandlers->get($form_state['display_id'])->validateOptionsForm($form['options'], $form_state);
$form_state['view']->getExecutable()->displayHandlers->get($form_state['display_id'])->validateOptionsForm($form['options'], $form_state);
if (form_get_errors()) {
$form_state['rerender'] = TRUE;
......@@ -109,7 +109,7 @@ public function validateForm(array &$form, array &$form_state) {
* Overrides \Drupal\views_ui\Form\Ajax\ViewsFormBase::submitForm().
*/
public function submitForm(array &$form, array &$form_state) {
$form_state['view']->get('executable')->displayHandlers->get($form_state['display_id'])->submitOptionsForm($form['options'], $form_state);
$form_state['view']->getExecutable()->displayHandlers->get($form_state['display_id'])->submitOptionsForm($form['options'], $form_state);
$form_state['view']->cacheSet();
}
......
......@@ -53,7 +53,7 @@ public function buildForm(array $form, array &$form_state) {
$type = $form_state['type'];
$types = ViewExecutable::viewsHandlerTypes();
$executable = $view->get('executable');
$executable = $view->getExecutable();
$executable->setDisplay($display_id);
$display = &$executable->displayHandlers->get($display_id);
$form['#title'] = t('Rearrange @type', array('@type' => $types[$type]['ltitle']));
......@@ -134,7 +134,7 @@ public function buildForm(array $form, array &$form_state) {
*/
public function submitForm(array &$form, array &$form_state) {
$types = ViewExecutable::viewsHandlerTypes();
$display = &$form_state['view']->get('executable')->displayHandlers->get($form_state['display_id']);
$display = &$form_state['view']->getExecutable()->displayHandlers->get($form_state['display_id']);
$old_fields = $display->getOption($types[$form_state['type']]['plural']);
$new_fields = $order = array();
......
......@@ -38,7 +38,7 @@ public function buildForm(array $form, array &$form_state) {
$type = 'filter';
$types = ViewExecutable::viewsHandlerTypes();
$executable = $view->get('executable');
$executable = $view->getExecutable();
if (!$executable->setDisplay($display_id)) {
views_ajax_render(t('Invalid display id @display', array('@display' => $display_id)));
}
......@@ -212,7 +212,7 @@ public function buildForm(array $form, array &$form_state) {
*/
public function submitForm(array &$form, array &$form_state) {
$types = ViewExecutable::viewsHandlerTypes();
$display = &$form_state['view']->get('executable')->displayHandlers->get($form_state['display_id']);
$display = &$form_state['view']->getExecutable()->displayHandlers->get($form_state['display_id']);
$remember_groups = array();
if (!empty($form_state['view']->form_cache)) {
......
......@@ -101,7 +101,7 @@ public static function getAdminCSS() {
* The display_id which is edited on the current request.
*/
public function getDisplayTabs(ViewUI $view) {
$executable = $view->get('executable');
$executable = $view->getExecutable();
$executable->initDisplay();
$display_id = $this->displayID;
$tabs = array();
......@@ -160,7 +160,7 @@ public function isDefaultDisplayShown(ViewUI $view) {
$advanced_mode = config('views.settings')->get('ui.show.master_display');
// For other users, show the default display only if there are no others, and
// hide it if there's at least one "real" display.
$additional_displays = (count($view->get('executable')->displayHandlers) == 1);
$additional_displays = (count($view->getExecutable()->displayHandlers) == 1);
return $advanced_mode || $additional_displays;
}
......
......@@ -237,7 +237,7 @@ protected function getDisplaysList(EntityInterface $view) {
*/
protected function getDisplayPaths(EntityInterface $view) {
$all_paths = array();
$executable = $view->get('executable');
$executable = $view->getExecutable();
$executable->initDisplay();
foreach ($executable->displayHandlers as $display) {
if ($display->hasPath()) {
......
......@@ -753,7 +753,7 @@ public function cacheSet() {
// Let any future object know that this view has changed.
$this->changed = TRUE;
$executable = $this->get('executable');
$executable = $this->getExecutable();
if (isset($executable->current_display)) {
// Add the knowledge of the changed display, too.
$this->changed_display[$executable->current_display] = TRUE;
......
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