function CustomAccessCheck::access

Same name in other branches
  1. 9 core/lib/Drupal/Core/Access/CustomAccessCheck.php \Drupal\Core\Access\CustomAccessCheck::access()
  2. 10 core/lib/Drupal/Core/Access/CustomAccessCheck.php \Drupal\Core\Access\CustomAccessCheck::access()
  3. 11.x core/lib/Drupal/Core/Access/CustomAccessCheck.php \Drupal\Core\Access\CustomAccessCheck::access()

Checks access for the account and route using the custom access checker.

Parameters

\Symfony\Component\Routing\Route $route: The route.

\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match object to be checked.

\Drupal\Core\Session\AccountInterface $account: The account being checked.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

File

core/lib/Drupal/Core/Access/CustomAccessCheck.php, line 63

Class

CustomAccessCheck
Defines an access checker that allows specifying a custom method for access.

Namespace

Drupal\Core\Access

Code

public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
    try {
        $callable = $this->controllerResolver
            ->getControllerFromDefinition($route->getRequirement('_custom_access'));
    } catch (\InvalidArgumentException $e) {
        // The custom access controller method was not found.
        throw new \BadMethodCallException(sprintf('The "%s" method is not callable as a _custom_access callback in route "%s"', $route->getRequirement('_custom_access'), $route->getPath()));
    }
    $arguments_resolver = $this->argumentsResolverFactory
        ->getArgumentsResolver($route_match, $account);
    $arguments = $arguments_resolver->getArguments($callable);
    return call_user_func_array($callable, $arguments);
}

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