You are here

public function Url::access in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Url.php \Drupal\Core\Url::access()

Checks this Url object against applicable access check services.

Determines whether the route is accessible or not.

Parameters

\Drupal\Core\Session\AccountInterface|null $account: (optional) Run access checks for this account. NULL for the current user.

bool $return_as_object: (optional) Defaults to FALSE.

Return value

bool|\Drupal\Core\Access\AccessResultInterface The access result. Returns a boolean if $return_as_object is FALSE (this is the default) and otherwise an AccessResultInterface object. When a boolean is returned, the result of AccessInterface::isAllowed() is returned, i.e. TRUE means access is explicitly allowed, FALSE means access is either explicitly forbidden or "no opinion".

File

core/lib/Drupal/Core/Url.php, line 822

Class

Url
Defines an object that holds information about a URL.

Namespace

Drupal\Core

Code

public function access(AccountInterface $account = NULL, $return_as_object = FALSE) {
  if ($this
    ->isRouted()) {
    return $this
      ->accessManager()
      ->checkNamedRoute($this
      ->getRouteName(), $this
      ->getRouteParameters(), $account, $return_as_object);
  }
  return $return_as_object ? AccessResult::allowed() : TRUE;
}