function ViewExecutable::executeDisplay

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

Executes the given display, with the given arguments.

To be called externally by whatever mechanism invokes the view, such as a page callback, hook_block, etc.

This function should NOT be used by anything external as this returns data in the format specified by the display. It can also have other side effects that are only intended for the 'proper' use of the display, such as setting page titles.

If you simply want to view the display, use View::preview() instead.

Parameters

string $display_id: The display ID of the view to be executed.

string[] $args: The arguments to be passed to the view.

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 1679

Class

ViewExecutable
Represents a view as a whole.

Namespace

Drupal\views

Code

public function executeDisplay($display_id = NULL, $args = []) {
    if (empty($this->current_display) || $this->current_display != $this->chooseDisplay($display_id)) {
        if (!$this->setDisplay($display_id)) {
            return NULL;
        }
    }
    $this->preExecute($args);
    // Execute the view
    $output = $this->display_handler
        ->execute();
    $this->postExecute();
    return $output;
}

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