You are here

public function View::render in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/area/View.php \Drupal\views\Plugin\views\area\View::render()

Render the area.

Parameters

bool $empty: (optional) Indicator if view result is empty or not. Defaults to FALSE.

Return value

array In any case we need a valid Drupal render array to return.

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'])) {
    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 [];
    }
    $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(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 [];
}