function CheckProvider::loadCheck

Same name in other branches
  1. 9 core/lib/Drupal/Core/Access/CheckProvider.php \Drupal\Core\Access\CheckProvider::loadCheck()
  2. 8.9.x core/lib/Drupal/Core/Access/CheckProvider.php \Drupal\Core\Access\CheckProvider::loadCheck()
  3. 11.x core/lib/Drupal/Core/Access/CheckProvider.php \Drupal\Core\Access\CheckProvider::loadCheck()
1 call to CheckProvider::loadCheck()
CheckProvider::applies in core/lib/Drupal/Core/Access/CheckProvider.php
Determine which registered access checks apply to a route.

File

core/lib/Drupal/Core/Access/CheckProvider.php, line 113

Class

CheckProvider
Loads access checkers from the container.

Namespace

Drupal\Core\Access

Code

public function loadCheck($service_id) {
    if (empty($this->checks[$service_id])) {
        if (!in_array($service_id, $this->checkIds)) {
            throw new \InvalidArgumentException(sprintf('No check has been registered for %s', $service_id));
        }
        $check = $this->container
            ->get($service_id);
        if (!$check instanceof AccessInterface) {
            throw new AccessException('All access checks must implement AccessInterface.');
        }
        if (!is_callable([
            $check,
            $this->checkMethods[$service_id],
        ])) {
            throw new AccessException(sprintf('Access check method %s in service %s must be callable.', $this->checkMethods[$service_id], $service_id));
        }
        $this->checks[$service_id] = $check;
    }
    return [
        $this->checks[$service_id],
        $this->checkMethods[$service_id],
    ];
}

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