You are here

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

A custom access check for menu items page.

Parameters

\Drupal\Core\Session\AccountInterface $account: Run access checks for this account.

\Drupal\menu_link_content\Entity\MenuLinkContent $menu_link_content: Run access checks for this menu item object.

Return value

\Drupal\Core\Access\AccessResult The access result.

Overrides MenuAdminPerMenuAccessInterface::menuItemAccess

File

src/Access/MenuAdminPerMenuAccess.php, line 69

Class

MenuAdminPerMenuAccess
Checks access for displaying administer menu pages.

Namespace

Drupal\menu_admin_per_menu\Access

Code

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