function ViewExecutable::access

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

Determines if the given user has access to the view.

Note that this sets the display handler if it hasn't been set.

Parameters

string $displays: The machine name of the display.

\Drupal\Core\Session\AccountInterface $account: The user object.

Return value

bool TRUE if the user has access to the view, FALSE otherwise.

File

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

Class

ViewExecutable
Represents a view as a whole.

Namespace

Drupal\views

Code

public function access($displays = NULL, $account = NULL) {
    // No one should have access to disabled views.
    if (!$this->storage
        ->status()) {
        return FALSE;
    }
    if (!isset($this->current_display)) {
        $this->initDisplay();
    }
    if (!$account) {
        $account = $this->user;
    }
    // We can't use choose_display() here because that function
    // calls this one.
    $displays = (array) $displays;
    foreach ($displays as $display_id) {
        if ($this->displayHandlers
            ->has($display_id)) {
            if (($display = $this->displayHandlers
                ->get($display_id)) && $display->access($account)) {
                return TRUE;
            }
        }
    }
    return FALSE;
}

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