function Views::getViewResult

Same name and namespace in other branches
  1. main core/modules/views/src/Views.php \Drupal\views\Views::getViewResult()

Get the result of a view.

Parameters

string $name: The name of the view to retrieve the data from.

string|null $display_id: The display ID. On the edit page for the view in question, you'll find a list of displays at the left side of the control area. "Default" will be at the top of that list. Hover your cursor over the name of the display you want to use. A URL will appear in the status bar of your browser. This is usually at the bottom of the window, in the chrome. Everything after #views-tab- is the display ID, e.g. page_1.

mixed ...$args: Any additional parameters will be passed as arguments.

Return value

array An array containing an object for each view item.

1 call to Views::getViewResult()
views_get_view_result in core/modules/views/views.module
Get the result of a view.

File

core/modules/views/src/Views.php, line 580

Class

Views
Static service container wrapper for views.

Namespace

Drupal\views

Code

public static function getViewResult(string $name, string|null $display_id = NULL, mixed ...$args) : array {
  $view = static::getView($name);
  if (is_object($view)) {
    if (is_array($args)) {
      $view->setArguments($args);
    }
    if (is_string($display_id)) {
      $view->setDisplay($display_id);
    }
    else {
      $view->initDisplay();
    }
    $view->preExecute();
    $view->execute();
    return $view->result;
  }
  return [];
}

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