class CRMCoreAccess in CRM Core 8
Same name and namespace in other branches
- 8.3 src/Access/CRMCoreAccess.php \Drupal\crm_core\Access\CRMCoreAccess
- 8.2 src/Access/CRMCoreAccess.php \Drupal\crm_core\Access\CRMCoreAccess
Check access for crm_core.
Hierarchy
- class \Drupal\crm_core\Access\CRMCoreAccess implements ContainerInjectionInterface, AccessInterface
Expanded class hierarchy of CRMCoreAccess
File
- src/
Access/ CRMCoreAccess.php, line 19
Namespace
Drupal\crm_core\AccessView source
class CRMCoreAccess implements RoutingAccessInterface, ContainerInjectionInterface {
/**
* The menu link tree manager.
*
* @var \Drupal\Core\Menu\MenuLinkTreeInterface
*/
protected $menuTree;
/**
* The access manager.
*
* @var \Drupal\Core\Access\AccessManagerInterface
*/
protected $accessManager;
/**
* CRMCoreAccess constructor.
*
* @param \Drupal\Core\Menu\MenuLinkTreeInterface $menu_tree
* The menu link tree manager.
* @param \Drupal\Core\Access\AccessManagerInterface $access_manager
* The access manager.
*/
public function __construct(MenuLinkTreeInterface $menu_tree, AccessManagerInterface $access_manager) {
$this->menuTree = $menu_tree;
$this->accessManager = $access_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('menu.link_tree'), $container
->get('access_manager'));
}
/**
* Checks access for CRM Core overview.
*
* @param \Symfony\Component\Routing\Route $route
* The route to check against.
* @param \Drupal\Core\Session\AccountInterface $account
* The account being checked.
*
* @return \Drupal\Core\Access\AccessResult
* The access result.
*/
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();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CRMCoreAccess:: |
protected | property | The access manager. | |
CRMCoreAccess:: |
protected | property | The menu link tree manager. | |
CRMCoreAccess:: |
public | function | Checks access for CRM Core overview. | |
CRMCoreAccess:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
CRMCoreAccess:: |
public | function | CRMCoreAccess constructor. |