diff --git a/core/modules/views/src/Plugin/views/area/View.php b/core/modules/views/src/Plugin/views/area/View.php index 8ef480b..d8ea5f5 100644 --- a/core/modules/views/src/Plugin/views/area/View.php +++ b/core/modules/views/src/Plugin/views/area/View.php @@ -106,35 +106,15 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function render($empty = FALSE) { - if (!empty($this->options['view_to_insert'])) { - list($view_name, $display_id) = explode(':', $this->options['view_to_insert']); - - $view = $this->viewStorage->load($view_name)->getExecutable(); - - if (empty($view) || !$view->access($display_id)) { - return array(); - } - $view->setDisplay($display_id); - - // Avoid recursion - $view->parent_views += $this->view->parent_views; - $view->parent_views[] = "$view_name:$display_id"; - - // Check if the view is part of the parent views of this view - $search = "$view_name:$display_id"; - if (in_array($search, $this->view->parent_views)) { - drupal_set_message(t("Recursion detected in view @view display @display.", array('@view' => $view_name, '@display' => $display_id)), 'error'); + if ($view = $this->loadView()) { + if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) { + $output = $view->preview(NULL, $this->view->args); } else { - if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) { - $output = $view->preview($display_id, $this->view->args); - } - else { - $output = $view->preview($display_id); - } - $this->isEmpty = $view->display_handler->outputIsEmpty(); - return $output; + $output = $view->preview(NULL); } + $this->isEmpty = $view->display_handler->outputIsEmpty(); + return $output; } return array(); } @@ -167,4 +147,39 @@ public function calculateDependencies() { return $dependencies; } + /** + * Loads the view used for rendering. + * + * @return \Drupal\views\ViewExecutable|NULL + * The loaded view or NULL, in case the view was not loadable / recursion + * got detected / access got denied. + */ + protected function loadView() { + if (empty($this->options['view_to_insert'])) { + return; + } + list($view_name, $display_id) = explode(':', $this->options['view_to_insert']); + + /** @var \Drupal\views\ViewExecutable $view */ + $view = $this->viewStorage->load($view_name)->getExecutable(); + + if (empty($view) || !$view->access($display_id)) { + return array(); + } + $view->setDisplay($display_id); + + // Avoid recursion. + $view->parent_views += $this->view->parent_views; + $view->parent_views[] = "$view_name:$display_id"; + + // Check if the view is part of the parent views of this view. + $search = "$view_name:$display_id"; + if (in_array($search, $this->view->parent_views)) { + drupal_set_message($this->t("Recursion detected in view @view display @display.", array('@view' => $view_name, '@display' => $display_id)), 'error'); + return; + } + + return $view; + } + }