You are here

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

A custom access check for menu link page.

Parameters

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

\Drupal\Core\Menu\MenuLinkInterface $menu_link_plugin: Run access checks for this menu link object.

Return value

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

Overrides MenuAdminPerMenuAccessInterface::menuLinkAccess

File

src/Access/MenuAdminPerMenuAccess.php, line 85

Class

MenuAdminPerMenuAccess
Checks access for displaying administer menu pages.

Namespace

Drupal\menu_admin_per_menu\Access

Code

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