class MenuAdminPerMenuAccess in Menu Admin per Menu 8
Checks access for displaying administer menu pages.
Hierarchy
- class \Drupal\menu_admin_per_menu\Access\MenuAdminPerMenuAccess implements MenuAdminPerMenuAccessInterface
Expanded class hierarchy of MenuAdminPerMenuAccess
2 files declare their use of MenuAdminPerMenuAccess
- MenuAdminPerMenuController.php in src/
Controller/ MenuAdminPerMenuController.php - MenuSelection.php in src/
Plugin/ EntityReferenceSelection/ MenuSelection.php
1 string reference to 'MenuAdminPerMenuAccess'
1 service uses MenuAdminPerMenuAccess
File
- src/
Access/ MenuAdminPerMenuAccess.php, line 15
Namespace
Drupal\menu_admin_per_menu\AccessView source
class MenuAdminPerMenuAccess implements MenuAdminPerMenuAccessInterface {
/**
* {@inheritdoc}
*/
public function getPerMenuPermissions(AccountInterface $account) {
$perms_menu =& drupal_static(__FUNCTION__, []);
if (!isset($perms_menu[$account
->id()])) {
$menus = menu_ui_get_menus();
foreach ($menus as $name => $title) {
$permission = 'administer ' . $name . ' menu items';
if ($account
->hasPermission($permission)) {
$perms_menu[$account
->id()][$permission] = $name;
}
}
$user_perms_menu = $perms_menu[$account
->id()] ?? [];
\Drupal::moduleHandler()
->alter('menu_admin_per_menu_get_permissions', $user_perms_menu, $account);
$perms_menu[$account
->id()] = $user_perms_menu;
}
return $perms_menu[$account
->id()] ?? [];
}
/**
* {@inheritdoc}
*/
public function menusOverviewAccess(AccountInterface $account) {
if ($account
->hasPermission('administer menu')) {
return AccessResult::allowed();
}
$permissions = $this::getPerMenuPermissions($account);
if ($account
->hasPermission('administer menu') || $permissions) {
return AccessResult::allowed();
}
return AccessResult::neutral();
}
/**
* {@inheritdoc}
*/
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();
}
/**
* {@inheritdoc}
*/
public function menuItemAccess(AccountInterface $account, MenuLinkContent $menu_link_content = NULL) {
if (!$menu_link_content instanceof MenuLinkContent) {
return AccessResult::neutral();
}
$permission = 'administer ' . $menu_link_content
->getMenuName() . ' menu items';
$permissions = $this::getPerMenuPermissions($account);
if ($account
->hasPermission('administer menu') || isset($permissions[$permission])) {
return AccessResult::allowed();
}
return AccessResult::neutral();
}
/**
* {@inheritdoc}
*/
public function menuLinkAccess(AccountInterface $account, MenuLinkInterface $menu_link_plugin = NULL) {
if (!$menu_link_plugin instanceof MenuLinkInterface) {
return AccessResult::neutral();
}
$permission = 'administer ' . $menu_link_plugin
->getMenuName() . ' menu items';
$permissions = $this::getPerMenuPermissions($account);
if ($account
->hasPermission('administer menu') || isset($permissions[$permission])) {
return AccessResult::allowed();
}
return AccessResult::neutral();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MenuAdminPerMenuAccess:: |
public | function |
Return array of all specific menu permissions. Overrides MenuAdminPerMenuAccessInterface:: |
|
MenuAdminPerMenuAccess:: |
public | function |
A custom access check for menu page and add link page. Overrides MenuAdminPerMenuAccessInterface:: |
|
MenuAdminPerMenuAccess:: |
public | function |
A custom access check for menu items page. Overrides MenuAdminPerMenuAccessInterface:: |
|
MenuAdminPerMenuAccess:: |
public | function |
A custom access check for menu link page. Overrides MenuAdminPerMenuAccessInterface:: |
|
MenuAdminPerMenuAccess:: |
public | function |
A custom access check for menu overview page. Overrides MenuAdminPerMenuAccessInterface:: |