diff --git a/core/modules/views_ui/src/ViewUI.php b/core/modules/views_ui/src/ViewUI.php index ae4f5ca..509c800 100644 --- a/core/modules/views_ui/src/ViewUI.php +++ b/core/modules/views_ui/src/ViewUI.php @@ -14,6 +14,7 @@ use Drupal\Core\EventSubscriber\AjaxResponseSubscriber; use Drupal\Core\Form\FormBuilderInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Render\BubbleableMetadata; use Drupal\Core\Url; use Drupal\views\Views; use Drupal\Core\Entity\EntityStorageInterface; @@ -544,6 +545,8 @@ public function renderPreview($display_id, $args = array()) { $request_stack = \Drupal::requestStack(); $current_request = $request_stack->getCurrentRequest(); $executable = $this->getExecutable(); + /** @var \Drupal\Core\Render\RendererInterface $renderer */ + $renderer = \Drupal::service('renderer'); // Determine where the query and performance statistics should be output. $config = \Drupal::config('views.settings'); @@ -852,6 +855,17 @@ public function renderPreview($display_id, $args = array()) { ]; } + if (!empty($output['preview'])) { + // We render the preview now, in order to render it in the context of the + // previous setup request, because for example pager links depend on the + // "current" URL. + $elements = $output['preview']; + $output['preview'] = [ + '#markup' => $renderer->renderPlain($elements), + ]; + BubbleableMetadata::createFromRenderArray($elements)->applyTo($output['preview']); + } + // Ensure that we just remove an additional request we pushed earlier. // This could happen if $errors was not empty. if ($request_stack->getCurrentRequest() != $current_request) {