function ViewExecutable::preview

Same name in other branches
  1. 9 core/modules/views/src/ViewExecutable.php \Drupal\views\ViewExecutable::preview()
  2. 8.9.x core/modules/views/src/ViewExecutable.php \Drupal\views\ViewExecutable::preview()
  3. 11.x core/modules/views/src/ViewExecutable.php \Drupal\views\ViewExecutable::preview()

Previews the given display, with the given arguments.

To be called externally, probably by an AJAX handler of some flavor. Can also be called when views are embedded, as this guarantees normalized output.

This function does not do any access checks on the view. It is the responsibility of the caller to check $view->access() or implement other access logic. To render the view normally with access checks, use views_embed_view() instead.

Return value

array|null A renderable array containing the view output or NULL if the display ID of the view to be executed doesn't exist.

File

core/modules/views/src/ViewExecutable.php, line 1711

Class

ViewExecutable
Represents a view as a whole.

Namespace

Drupal\views

Code

public function preview($display_id = NULL, $args = []) {
    if (empty($this->current_display) || !empty($display_id) && $this->current_display != $display_id) {
        if (!$this->setDisplay($display_id)) {
            return FALSE;
        }
    }
    $this->preview = TRUE;
    $this->preExecute($args);
    // Preview the view.
    $output = $this->display_handler
        ->preview();
    $this->postExecute();
    return $output;
}

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