You are here

public function CRMCoreAccess::access in CRM Core 8.3

Same name and namespace in other branches
  1. 8 src/Access/CRMCoreAccess.php \Drupal\crm_core\Access\CRMCoreAccess::access()
  2. 8.2 src/Access/CRMCoreAccess.php \Drupal\crm_core\Access\CRMCoreAccess::access()

Checks access for CRM Core overview.

Parameters

\Symfony\Component\Routing\Route $route: The route to check against.

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

Return value

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

1 string reference to 'CRMCoreAccess::access'
crm_core.routing.yml in ./crm_core.routing.yml
crm_core.routing.yml

File

src/Access/CRMCoreAccess.php, line 69

Class

CRMCoreAccess
Check access for crm_core.

Namespace

Drupal\crm_core\Access

Code

public function access(Route $route, AccountInterface $account) {
  $path = $route
    ->getPath();
  $route = Url::fromUri('internal:' . $path);
  $parameters = new MenuTreeParameters();
  $parameters
    ->setRoot($route
    ->getRouteName())
    ->excludeRoot()
    ->setTopLevelOnly()
    ->onlyEnabledLinks();
  $tree = $this->menuTree
    ->load(NULL, $parameters);
  $manipulators = [
    [
      'callable' => 'menu.default_tree_manipulators:checkAccess',
    ],
    [
      'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
    ],
  ];
  $tree = $this->menuTree
    ->transform($tree, $manipulators);
  foreach ($tree as $element) {
    $route_name = $element->link
      ->getPluginId();
    if ($this->accessManager
      ->checkNamedRoute($route_name, [], $account)) {
      return AccessResult::allowed();
    }
  }
  return AccessResult::forbidden();
}