Commit 547fada2 authored by damiankloip's avatar damiankloip Committed by tim.plunkett

Issue #1791238 by damiankloip: Remove ViewStorageController::save().

parent df8a0e21
......@@ -175,10 +175,6 @@ protected function createTests() {
$this->assertIdentical($values[$property], $created->{$property}, format_string('Property value: @property matches configuration value.', array('@property' => $property)));
}
// Test created displays.
foreach ($created->display as $key => $display) {
}
// Check the uuid of the loaded View.
$created->set('name', 'glossary_new');
$created->save();
......@@ -252,7 +248,7 @@ protected function displayTests() {
// Ensure the right display_plugin is created/instantiated.
$this->assertEqual($new_display['display_plugin'], 'page', 'New page display "test" uses the right display plugin.');
$this->assertTrue($view->executable->displayHandlers[$new_display['id']] instanceof Page, 'New page display "test" uses the right display plugin.');
$this->assertTrue($view->getExecutable()->displayHandlers[$new_display['id']] instanceof Page, 'New page display "test" uses the right display plugin.');
$view->set('name', 'frontpage_new');
......@@ -371,18 +367,18 @@ protected function displayMethodTests() {
$display = $view->newDisplay('page');
$this->assertTrue($display instanceof \Drupal\views\Plugin\views\display\Page);
$this->assertTrue($view->executable->displayHandlers['page_1'] instanceof \Drupal\views\Plugin\views\display\Page);
$this->assertTrue($view->executable->displayHandlers['page_1']->default_display instanceof \Drupal\views\Plugin\views\display\DefaultDisplay);
$this->assertTrue($view->getExecutable()->displayHandlers['page_1'] instanceof \Drupal\views\Plugin\views\display\Page);
$this->assertTrue($view->getExecutable()->displayHandlers['page_1']->default_display instanceof \Drupal\views\Plugin\views\display\DefaultDisplay);
$display = $view->newDisplay('page');
$this->assertTrue($display instanceof \Drupal\views\Plugin\views\display\Page);
$this->assertTrue($view->executable->displayHandlers['page_2'] instanceof \Drupal\views\Plugin\views\display\Page);
$this->assertTrue($view->executable->displayHandlers['page_2']->default_display instanceof \Drupal\views\Plugin\views\display\DefaultDisplay);
$this->assertTrue($view->getExecutable()->displayHandlers['page_2'] instanceof \Drupal\views\Plugin\views\display\Page);
$this->assertTrue($view->getExecutable()->displayHandlers['page_2']->default_display instanceof \Drupal\views\Plugin\views\display\DefaultDisplay);
$display = $view->newDisplay('feed');
$this->assertTrue($display instanceof \Drupal\views\Plugin\views\display\Feed);
$this->assertTrue($view->executable->displayHandlers['feed_1'] instanceof \Drupal\views\Plugin\views\display\Feed);
$this->assertTrue($view->executable->displayHandlers['feed_1']->default_display instanceof \Drupal\views\Plugin\views\display\DefaultDisplay);
$this->assertTrue($view->getExecutable()->displayHandlers['feed_1'] instanceof \Drupal\views\Plugin\views\display\Feed);
$this->assertTrue($view->getExecutable()->displayHandlers['feed_1']->default_display instanceof \Drupal\views\Plugin\views\display\DefaultDisplay);
// Tests item related methods().
$view = $this->controller->create(array('base_table' => 'views_test_data'));
......
......@@ -1818,12 +1818,6 @@ public function createDuplicate() {
/**
* Safely clone a view.
*
* Because views are complicated objects within objects, and PHP loves to
* do references to everything, if a View is not properly and safely
* cloned it will still have references to the original view, and can
* actually cause the original view to point to objects in the cloned
* view. This gets ugly fast.
*
* This will completely wipe a view clean so it can be considered fresh.
*
* @return Drupal\views\ViewExecutable
......@@ -1831,17 +1825,7 @@ public function createDuplicate() {
*/
public function cloneView() {
$clone = clone $this->storage;
$keys = array('executable', 'current_display', 'display_handler', 'displayHandlers', 'build_info', 'built', 'executed', 'attachment_before', 'attachment_after', 'field', 'argument', 'filter', 'sort', 'relationship', 'header', 'footer', 'empty', 'query', 'inited', 'style_plugin', 'plugin_name', 'exposed_data', 'exposed_input', 'exposed_widgets', 'many_to_one_tables', 'feed_icon');
foreach ($keys as $key) {
unset($clone->$key);
}
$clone = $clone->getExecutable();
$clone->built = $clone->executed = FALSE;
$clone->build_info = array();
$clone->attachment_before = '';
$clone->attachment_after = '';
$clone->result = array();
$clone = $clone->getExecutable(TRUE);
return $clone;
}
......
......@@ -94,20 +94,18 @@ class ViewStorage extends ConfigEntityBase implements ViewStorageInterface {
public $disabled = FALSE;
/**
* Stores a reference to the executable version of this view.
* The UUID for this entity.
*
* @var Drupal\views\ViewExecutable
* @var string
*/
public $executable;
public $uuid = NULL;
/**
* A copy of the original entity.
*
* @todo This should be moved to Drupal\Core\Entity\Entity.
* Stores a reference to the executable version of this view.
*
* @var Drupal\Core\Entity\EntityInterface
* @var Drupal\views\ViewExecutable
*/
public $original;
protected $executable;
/**
* The module implementing this view.
......@@ -129,11 +127,14 @@ public function setExecutable(ViewExecutable $executable) {
/**
* Retrieves the executable version of this view.
*
* @param bool $reset
* Get a new Drupal\views\ViewExecutable instance.
*
* @return Drupal\views\ViewExecutable
* The executable version of this view.
*/
public function getExecutable() {
if (!isset($this->executable)) {
public function getExecutable($reset = FALSE) {
if (!isset($this->executable) || $reset) {
$this->setExecutable(new ViewExecutable($this));
}
return $this->executable;
......@@ -150,8 +151,7 @@ public function getExecutable() {
* @see Drupal\views\ViewExecutable::initDisplay()
*/
public function initDisplay($reset = FALSE) {
$this->getExecutable();
$this->executable->initDisplay($reset);
$this->getExecutable()->initDisplay($reset);
}
/**
......@@ -323,8 +323,7 @@ protected function generateDisplayId($plugin_id) {
*/
public function &newDisplay($plugin_id = 'page', $title = NULL, $id = NULL) {
$id = $this->addDisplay($plugin_id, $title, $id);
$this->getExecutable();
return $this->executable->newDisplay($id);
return $this->getExecutable()->newDisplay($id);
}
/**
......
......@@ -58,87 +58,12 @@ protected function attachLoad(&$queried_entities, $revision_id = FALSE) {
}
/**
* Overrides Drupal\config\ConfigStorageController::save().
*
* This currently replaces the reflection code with a static array of
* properties to be set on the config object. This can be removed when the
* view storage is isolated so the ReflectionClass can work.
* Overrides Drupal\config\ConfigStorageController::postSave().
*/
public function save(EntityInterface $entity) {
$prefix = $this->entityInfo['config prefix'] . '.';
// Load the stored entity, if any, and rename it.
if ($entity->getOriginalID()) {
$id = $entity->getOriginalID();
}
else {
$id = $entity->id();
}
$config = config($prefix . $id);
$config->setName($prefix . $entity->id());
if (!$config->isNew() && !isset($entity->original)) {
$entity->original = entity_load_unchanged($this->entityType, $id);
}
$this->preSave($entity);
$this->invokeHook('presave', $entity);
// @todo This temp measure will be removed once we have a better way or
// separation of storage and the executed view.
$config_properties = array (
'disabled',
'api_version',
'name',
'description',
'tag',
'base_table',
'human_name',
'core',
'display',
'uuid',
'module',
);
foreach ($config_properties as $property) {
if ($property == 'display') {
$displays = array();
foreach ($entity->display as $key => $display) {
$displays[$key] = array(
'display_options' => $display['display_options'],
'display_plugin' => $display['display_plugin'],
'id' => $display['id'],
'display_title' => $display['display_title'],
'position' => isset($display['position']) ? $display['position'] : 0,
);
}
$config->set('display', $displays);
}
else {
$config->set($property, $entity->$property);
}
}
if (!$config->isNew()) {
$return = SAVED_NEW;
$config->save();
$this->postSave($entity, TRUE);
$this->invokeHook('update', $entity);
}
else {
$return = SAVED_UPDATED;
$config->save();
$entity->enforceIsNew(FALSE);
$this->postSave($entity, FALSE);
$this->invokeHook('insert', $entity);
}
public function postSave(EntityInterface $entity, $update) {
parent::postSave($entity, $update);
// Clear caches.
views_invalidate_cache();
unset($entity->original);
return $return;
}
/**
......
......@@ -698,7 +698,7 @@ function views_block_info() {
}
$view->initDisplay();
foreach ($view->executable->displayHandlers as $display) {
foreach ($view->getExecutable()->displayHandlers as $display) {
if (isset($display) && !empty($display->definition['uses_hook_block'])) {
$result = $display->executeHookBlockList();
......
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