Commit 97969786 authored by webchick's avatar webchick

Issue #1858054 by tim.plunkett, dawehner: Remove ViewExecutable::cloneView().

parent c437f67d
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
namespace Drupal\views\Plugin\views\display; namespace Drupal\views\Plugin\views\display;
use Drupal\views\ViewExecutable;
use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation; use Drupal\Core\Annotation\Translation;
...@@ -230,7 +231,7 @@ public function submitOptionsForm(&$form, &$form_state) { ...@@ -230,7 +231,7 @@ public function submitOptionsForm(&$form, &$form_state) {
/** /**
* Attach to another view. * Attach to another view.
*/ */
public function attachTo($display_id) { public function attachTo(ViewExecutable $view, $display_id) {
$displays = $this->getOption('displays'); $displays = $this->getOption('displays');
if (empty($displays[$display_id])) { if (empty($displays[$display_id])) {
...@@ -241,10 +242,6 @@ public function attachTo($display_id) { ...@@ -241,10 +242,6 @@ public function attachTo($display_id) {
return; return;
} }
// Get a fresh view because our current one has a lot of stuff on it because it's
// already been executed.
$view = $this->view->cloneView();
$args = $this->getOption('inherit_arguments') ? $this->view->args : array(); $args = $this->getOption('inherit_arguments') ? $this->view->args : array();
$view->setArguments($args); $view->setArguments($args);
$view->setDisplay($this->display['id']); $view->setDisplay($this->display['id']);
......
...@@ -380,7 +380,7 @@ public function usesAreas() { ...@@ -380,7 +380,7 @@ public function usesAreas() {
/** /**
* Allow displays to attach to other views. * Allow displays to attach to other views.
*/ */
public function attachTo($display_id) { } public function attachTo(ViewExecutable $view, $display_id) { }
/** /**
* Static member function to list which sections are defaultable * Static member function to list which sections are defaultable
......
...@@ -244,7 +244,7 @@ public function submitOptionsForm(&$form, &$form_state) { ...@@ -244,7 +244,7 @@ public function submitOptionsForm(&$form, &$form_state) {
/** /**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::attachTo(). * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::attachTo().
*/ */
public function attachTo($display_id) { public function attachTo(ViewExecutable $clone, $display_id) {
$displays = $this->getOption('displays'); $displays = $this->getOption('displays');
if (empty($displays[$display_id])) { if (empty($displays[$display_id])) {
return; return;
...@@ -254,7 +254,6 @@ public function attachTo($display_id) { ...@@ -254,7 +254,6 @@ public function attachTo($display_id) {
// attach a feed icon. // attach a feed icon.
$plugin = $this->getPlugin('style'); $plugin = $this->getPlugin('style');
if ($plugin) { if ($plugin) {
$clone = $this->view->cloneView();
$clone->setDisplay($this->display['id']); $clone->setDisplay($this->display['id']);
$clone->buildTitle(); $clone->buildTitle();
$plugin->attach_to($display_id, $this->getPath(), $clone->getTitle()); $plugin->attach_to($display_id, $this->getPath(), $clone->getTitle());
......
...@@ -1492,7 +1492,9 @@ public function attachDisplays() { ...@@ -1492,7 +1492,9 @@ public function attachDisplays() {
// Give other displays an opportunity to attach to the view. // Give other displays an opportunity to attach to the view.
foreach ($this->displayHandlers as $id => $display) { foreach ($this->displayHandlers as $id => $display) {
if (!empty($this->displayHandlers[$id])) { if (!empty($this->displayHandlers[$id])) {
$this->displayHandlers[$id]->attachTo($this->current_display); // Create a clone for the attachments to manipulate. 'static' refers to the current class name.
$cloned_view = new static($this->storage);
$this->displayHandlers[$id]->attachTo($cloned_view, $this->current_display);
} }
} }
$this->is_attachment = FALSE; $this->is_attachment = FALSE;
...@@ -1831,21 +1833,6 @@ public function createDuplicate() { ...@@ -1831,21 +1833,6 @@ public function createDuplicate() {
return entity_create('view', $data); return entity_create('view', $data);
} }
/**
* Safely clone a view.
*
* This will completely wipe a view clean so it can be considered fresh.
*
* @return Drupal\views\ViewExecutable
* The cloned view.
*/
public function cloneView() {
$storage = clone $this->storage;
$executable = new ViewExecutable($storage);
$storage->set('executable', $executable);
return $executable;
}
/** /**
* Unset references so that a $view object may be properly garbage * Unset references so that a $view object may be properly garbage
* collected. * collected.
......
...@@ -479,11 +479,6 @@ function views_menu_alter(&$callbacks) { ...@@ -479,11 +479,6 @@ function views_menu_alter(&$callbacks) {
$our_paths[$path] = TRUE; $our_paths[$path] = TRUE;
} }
} }
}
// Save memory: Destroy those views.
foreach ($views as $data) {
list($view, $display_id) = $data;
$view->destroy(); $view->destroy();
} }
} }
...@@ -1411,21 +1406,12 @@ function views_get_applicable_views($type) { ...@@ -1411,21 +1406,12 @@ function views_get_applicable_views($type) {
continue; continue;
} }
// Loop on array keys because something seems to muck with $view->display // Check each display to see if it meets the criteria and is enabled.
// a bit in PHP4. $executable = $view->get('executable');
foreach (array_keys($display) as $id) { $executable->setDisplay();
$plugin = drupal_container()->get('plugin.manager.views.display')->getDefinition($display[$id]['display_plugin']); foreach ($executable->displayHandlers as $id => $handler) {
if (!empty($plugin[$type])) { if (!empty($handler->definition[$type]) && $handler->isEnabled()) {
// This view uses_hook_menu. Clone it so that different handlers $result[] = array($executable, $id);
// don't trip over each other, and add it to the list.
$v = $view->get('executable')->cloneView();
if ($v->setDisplay($id) && $v->display_handler->isEnabled()) {
$result[] = array($v, $id);
}
// In PHP 4.4.7 and presumably earlier, if we do not unset $v
// here, we will find that it actually overwrites references
// possibly due to shallow copying issues.
unset($v);
} }
} }
} }
......
...@@ -1460,8 +1460,7 @@ function views_ui_config_item_form($form, &$form_state) { ...@@ -1460,8 +1460,7 @@ function views_ui_config_item_form($form, &$form_state) {
// We want this relationship option to get saved even if the user // We want this relationship option to get saved even if the user
// skips submitting the form. // skips submitting the form.
$executable->setItemOption($display_id, $type, $id, 'relationship', $rel); $executable->setItemOption($display_id, $type, $id, 'relationship', $rel);
$temp_view = $view->cloneView(); views_ui_cache_set($view);
views_ui_cache_set($temp_view);
} }
$form['options']['relationship'] = array( $form['options']['relationship'] = array(
......
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