public function CRMCoreAccess::access in CRM Core 8
Same name and namespace in other branches
- 8.3 src/Access/CRMCoreAccess.php \Drupal\crm_core\Access\CRMCoreAccess::access()
- 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'
File
- src/
Access/ CRMCoreAccess.php, line 69
Class
- CRMCoreAccess
- Check access for crm_core.
Namespace
Drupal\crm_core\AccessCode
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();
}