You are here

public function MenuAdminPerMenuAccess::getPerMenuPermissions in Menu Admin per Menu 8

Return array of all specific menu permissions.

Parameters

\Drupal\Core\Session\AccountInterface $account: The user object for the user whose menu access is being checked.

Return value

array The array of allowed menus, keyed with permission.

Overrides MenuAdminPerMenuAccessInterface::getPerMenuPermissions

File

src/Access/MenuAdminPerMenuAccess.php, line 20

Class

MenuAdminPerMenuAccess
Checks access for displaying administer menu pages.

Namespace

Drupal\menu_admin_per_menu\Access

Code

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()] ?? [];
}