public function MenuAdminPerMenuAccess::menuAccess in Menu Admin per Menu 8
A custom access check for menu page and add link page.
Parameters
\Drupal\Core\Session\AccountInterface $account: Run access checks for this account.
\Drupal\system\Entity\Menu $menu: Run access checks for this menu object.
Return value
\Drupal\Core\Access\AccessResult The access result.
Overrides MenuAdminPerMenuAccessInterface::menuAccess
File
- src/
Access/ MenuAdminPerMenuAccess.php, line 56
Class
- MenuAdminPerMenuAccess
- Checks access for displaying administer menu pages.
Namespace
Drupal\menu_admin_per_menu\AccessCode
public function menuAccess(AccountInterface $account, Menu $menu) {
$permission = 'administer ' . $menu
->get('id') . ' menu items';
$permissions = $this::getPerMenuPermissions($account);
if ($account
->hasPermission('administer menu') || isset($permissions[$permission])) {
return AccessResult::allowed();
}
return AccessResult::neutral();
}