diff --git a/core/modules/views/src/ViewExecutable.php b/core/modules/views/src/ViewExecutable.php
index 6484a61..dc0d08d 100644
--- a/core/modules/views/src/ViewExecutable.php
+++ b/core/modules/views/src/ViewExecutable.php
@@ -2236,7 +2236,13 @@ public function calculateDependencies() {
* {@inheritdoc}
*/
public function serialize() {
- $storage = $this->storage instanceof ViewUI ? $this->storage : $this->storage->id();
+ if ($this->storage instanceof ViewUI) {
+ $storage = clone $this->storage;
+ }
+ else {
+ $storage = $this->storage->id();
+ }
+
return serialize([
$storage,
$this->current_display,
diff --git a/core/modules/views_ui/src/ViewUI.php b/core/modules/views_ui/src/ViewUI.php
index 3b5351b..71f1b1a 100644
--- a/core/modules/views_ui/src/ViewUI.php
+++ b/core/modules/views_ui/src/ViewUI.php
@@ -171,11 +171,6 @@ class ViewUI implements ViewEntityInterface {
public function __construct(ViewEntityInterface $storage, ViewExecutable $executable = NULL) {
$this->entityType = 'view';
$this->storage = $storage;
-
- if (!isset($executable)) {
- $executable = Views::executableFactory()->get($this);
- }
- $this->executable = $executable;
}
/**
@@ -258,7 +253,7 @@ public function standardSubmit($form, FormStateInterface $form_state) {
$display_id = $form_state->get('display_id');
if ($revert) {
// If it's revert just change the override and return.
- $display = &$this->executable->displayHandlers->get($display_id);
+ $display = &$this->getExecutable()->displayHandlers->get($display_id);
$display->optionsOverride($form, $form_state);
// Don't execute the normal submit handling but still store the changed view into cache.
@@ -272,7 +267,7 @@ public function standardSubmit($form, FormStateInterface $form_state) {
elseif ($was_defaulted && !$is_defaulted) {
// We were using the default display's values, but we're now overriding
// the default display and saving values specific to this display.
- $display = &$this->executable->displayHandlers->get($display_id);
+ $display = &$this->getExecutable()->displayHandlers->get($display_id);
// optionsOverride toggles the override of this section.
$display->optionsOverride($form, $form_state);
$display->submitOptionsForm($form, $form_state);
@@ -282,7 +277,7 @@ public function standardSubmit($form, FormStateInterface $form_state) {
// to go back to the default display.
// Overwrite the default display with the current form values, and make
// the current display use the new default values.
- $display = &$this->executable->displayHandlers->get($display_id);
+ $display = &$this->getExecutable()->displayHandlers->get($display_id);
// optionsOverride toggles the override of this section.
$display->optionsOverride($form, $form_state);
$display->submitOptionsForm($form, $form_state);
@@ -480,7 +475,7 @@ public function submitItemAdd($form, FormStateInterface $form_state) {
if ($was_defaulted && !$is_defaulted) {
// We were using the default display's values, but we're now overriding
// the default display and saving values specific to this display.
- $display = &$this->executable->displayHandlers->get($display_id);
+ $display = &$this->getExecutable()->displayHandlers->get($display_id);
// setOverride toggles the override of this section.
$display->setOverride($section);
}
@@ -489,7 +484,7 @@ public function submitItemAdd($form, FormStateInterface $form_state) {
// to go back to the default display.
// Overwrite the default display with the current form values, and make
// the current display use the new default values.
- $display = &$this->executable->displayHandlers->get($display_id);
+ $display = &$this->getExecutable()->displayHandlers->get($display_id);
// optionsOverride toggles the override of this section.
$display->setOverride($section);
}
@@ -502,7 +497,7 @@ public function submitItemAdd($form, FormStateInterface $form_state) {
if ($cut = strpos($field, '$')) {
$field = substr($field, 0, $cut);
}
- $id = $this->executable->addHandler($display_id, $type, $table, $field);
+ $id = $this->getExecutable()->addHandler($display_id, $type, $table, $field);
// check to see if we have group by settings
$key = $type;
@@ -515,7 +510,7 @@ public function submitItemAdd($form, FormStateInterface $form_state) {
'field' => $field,
);
$handler = Views::handlerManager($key)->getHandler($item);
- if ($this->executable->displayHandlers->get('default')->useGroupBy() && $handler->usesGroupBy()) {
+ if ($this->getExecutable()->displayHandlers->get('default')->useGroupBy() && $handler->usesGroupBy()) {
$this->addFormToStack('handler-group', $display_id, $type, $id);
}
@@ -579,11 +574,11 @@ public function renderPreview($display_id, $args = array()) {
$rows = array('query' => array(), 'statistics' => array());
- $errors = $this->executable->validate();
- $this->executable->destroy();
+ $errors = $this->getExecutable()->validate();
+ $this->getExecutable()->destroy();
if (empty($errors)) {
$this->ajax = TRUE;
- $this->executable->live_preview = TRUE;
+ $this->getExecutable()->live_preview = TRUE;
// AJAX happens via HTTP POST but everything expects exposed data to
// be in GET. Copy stuff but remove ajax-framework specific keys.
@@ -596,19 +591,19 @@ public function renderPreview($display_id, $args = array()) {
unset($exposed_input[$key]);
}
}
- $this->executable->setExposedInput($exposed_input);
+ $this->getExecutable()->setExposedInput($exposed_input);
- if (!$this->executable->setDisplay($display_id)) {
+ if (!$this->getExecutable()->setDisplay($display_id)) {
return [
'#markup' => t('Invalid display id @display', array('@display' => $display_id)),
];
}
- $this->executable->setArguments($args);
+ $this->getExecutable()->setArguments($args);
// Store the current view URL for later use:
- if ($this->executable->display_handler->getOption('path')) {
- $path = $this->executable->getUrl();
+ if ($this->getExecutable()->display_handler->getOption('path')) {
+ $path = $this->getExecutable()->getUrl();
}
// Make view links come back to preview.
@@ -645,7 +640,7 @@ public function renderPreview($display_id, $args = array()) {
}
// Execute/get the view preview.
- $preview = $this->executable->preview($display_id, $args);
+ $preview = $this->getExecutable()->preview($display_id, $args);
if ($show_additional_queries) {
$this->endQueryCapture();
@@ -659,13 +654,13 @@ public function renderPreview($display_id, $args = array()) {
// below the view preview.
if ($show_info || $show_query || $show_stats) {
// Get information from the preview for display.
- if (!empty($this->executable->build_info['query'])) {
+ if (!empty($this->getExecutable()->build_info['query'])) {
if ($show_query) {
- $query_string = $this->executable->build_info['query'];
+ $query_string = $this->getExecutable()->build_info['query'];
// Only the sql default class has a method getArguments.
$quoted = array();
- if ($this->executable->query instanceof Sql) {
+ if ($this->getExecutable()->query instanceof Sql) {
$quoted = $query_string->getArguments();
$connection = Database::getConnection();
foreach ($quoted as $key => $val) {
@@ -721,7 +716,7 @@ public function renderPreview($display_id, $args = array()) {
'#template' => "{% trans 'Title' %}",
),
),
- Xss::filterAdmin($this->executable->getTitle()),
+ Xss::filterAdmin($this->getExecutable()->getTitle()),
);
if (isset($path)) {
$path = \Drupal::l($path, Url::fromUri('user-path:/' . $path));
@@ -740,7 +735,7 @@ public function renderPreview($display_id, $args = array()) {
'#template' => "{% trans 'Query build time' %}",
),
),
- t('@time ms', array('@time' => intval($this->executable->build_time * 100000) / 100)),
+ t('@time ms', array('@time' => intval($this->getExecutable()->build_time * 100000) / 100)),
);
$rows['statistics'][] = array(
@@ -750,7 +745,7 @@ public function renderPreview($display_id, $args = array()) {
'#template' => "{% trans 'Query execute time' %}",
),
),
- t('@time ms', array('@time' => intval($this->executable->execute_time * 100000) / 100)),
+ t('@time ms', array('@time' => intval($this->getExecutable()->execute_time * 100000) / 100)),
);
$rows['statistics'][] = array(
@@ -760,7 +755,7 @@ public function renderPreview($display_id, $args = array()) {
'#template' => "{% trans 'View render time' %}",
),
),
- t('@time ms', array('@time' => intval($this->executable->render_time * 100000) / 100)),
+ t('@time ms', array('@time' => intval($this->getExecutable()->render_time * 100000) / 100)),
);
}
\Drupal::moduleHandler()->alter('views_preview_info', $rows, $this->executable);
@@ -899,6 +894,14 @@ public function __call($method, $args) {
}
/**
+ * Magic __clone behavior.
+ */
+ public function __clone() {
+ $this->storage = clone $this->storage;
+ $this->executable = NULL;
+ }
+
+ /**
* {@inheritdoc}
*/
public function &getDisplay($display_id) {
@@ -1129,6 +1132,10 @@ public static function postLoad(EntityStorageInterface $storage, array &$entitie
* {@inheritdoc}
*/
public function getExecutable() {
+ if (!isset($this->executable)) {
+ $this->executable = Views::executableFactory()->get($this);
+ }
+
return $this->executable;
}