function View::render

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/area/View.php \Drupal\views\Plugin\views\area\View::render()
  2. 8.9.x core/modules/views/src/Plugin/views/area/View.php \Drupal\views\Plugin\views\area\View::render()
  3. 10 core/modules/views/src/Plugin/views/area/View.php \Drupal\views\Plugin\views\area\View::render()

Overrides AreaPluginBase::render

File

core/modules/views/src/Plugin/views/area/View.php, line 103

Class

View
Views area handlers. Insert a view inside of an area.

Namespace

Drupal\views\Plugin\views\area

Code

public function render($empty = FALSE) {
    if (!empty($this->options['view_to_insert'])) {
        [
            $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 [];
        }
        $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::messenger()->addError($this->t("Recursion detected in view @view display @display.", [
                '@view' => $view_name,
                '@display' => $display_id,
            ]));
        }
        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;
        }
    }
    return [];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.