1. 8.5.x core/lib/Drupal/Core/Access/CustomAccessCheck.php CustomAccessCheck
  2. 8.0.x core/lib/Drupal/Core/Access/CustomAccessCheck.php CustomAccessCheck
  3. 8.1.x core/lib/Drupal/Core/Access/CustomAccessCheck.php CustomAccessCheck
  4. 8.2.x core/lib/Drupal/Core/Access/CustomAccessCheck.php CustomAccessCheck
  5. 8.3.x core/lib/Drupal/Core/Access/CustomAccessCheck.php CustomAccessCheck
  6. 8.4.x core/lib/Drupal/Core/Access/CustomAccessCheck.php CustomAccessCheck
  7. 8.6.x core/lib/Drupal/Core/Access/CustomAccessCheck.php CustomAccessCheck

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

You should only use it when you are sure that the access callback will not be reused. Good examples in core are Edit or Toolbar module.

The method is called on another instance of the controller class, so you cannot reuse any stored property of your actual controller instance used to generate the output.

Hierarchy

Expanded class hierarchy of CustomAccessCheck

1 file declares its use of CustomAccessCheck
1 string reference to 'CustomAccessCheck'
core.services.yml in core/core.services.yml
core/core.services.yml

File

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

Namespace

Drupal\Core\Access
View source
class CustomAccessCheck implements RoutingAccessInterface {

  /**
   * The controller resolver.
   *
   * @var \Drupal\Core\Controller\ControllerResolverInterface
   */
  protected $controllerResolver;

  /**
   * The arguments resolver.
   *
   * @var \Drupal\Core\Access\AccessArgumentsResolverFactoryInterface
   */
  protected $argumentsResolverFactory;

  /**
   * Constructs a CustomAccessCheck instance.
   *
   * @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver
   *   The controller resolver.
   * @param \Drupal\Core\Access\AccessArgumentsResolverFactoryInterface $arguments_resolver_factory
   *   The arguments resolver factory.
   */
  public function __construct(ControllerResolverInterface $controller_resolver, AccessArgumentsResolverFactoryInterface $arguments_resolver_factory) {
    $this->controllerResolver = $controller_resolver;
    $this->argumentsResolverFactory = $arguments_resolver_factory;
  }

  /**
   * Checks access for the account and route using the custom access checker.
   *
   * @param \Symfony\Component\Routing\Route $route
   *   The route.
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The route match object to be checked.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The account being checked.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
    $callable = $this->controllerResolver
      ->getControllerFromDefinition($route
      ->getRequirement('_custom_access'));
    $arguments_resolver = $this->argumentsResolverFactory
      ->getArgumentsResolver($route_match, $account);
    $arguments = $arguments_resolver
      ->getArguments($callable);
    return call_user_func_array($callable, $arguments);
  }

}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description Overrides
CustomAccessCheck::$argumentsResolverFactory protected property The arguments resolver.
CustomAccessCheck::$controllerResolver protected property The controller resolver.
CustomAccessCheck::access public function Checks access for the account and route using the custom access checker.
CustomAccessCheck::__construct public function Constructs a CustomAccessCheck instance.