You are here

protected function MenuPerRoleLinkTreeManipulator::bypassAccessCheck in Menu Per Role 8

Check if the user can bypass the access check.

Return value

bool TRUE if the Menu Per Role access check should be bypassed.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

1 call to MenuPerRoleLinkTreeManipulator::bypassAccessCheck()
MenuPerRoleLinkTreeManipulator::menuLinkCheckAccess in src/MenuPerRoleLinkTreeManipulator.php
Checks access for one menu link instance.

File

src/MenuPerRoleLinkTreeManipulator.php, line 115

Class

MenuPerRoleLinkTreeManipulator
Menu Per Role link tree manipulator service.

Namespace

Drupal\menu_per_role

Code

protected function bypassAccessCheck() : bool {
  $bypass_access_check = FALSE;
  $menu_per_role_settings = $this->config
    ->get('menu_per_role.settings');
  $admin_bypass_access_front = $menu_per_role_settings
    ->get('admin_bypass_access_front');
  $admin_bypass_access_admin = $menu_per_role_settings
    ->get('admin_bypass_access_admin');
  $context_is_admin = $this->adminContext
    ->isAdminRoute();
  $user_is_admin = $this
    ->isUserAdmin();

  // Admin user access check bypass.
  if ($user_is_admin) {
    if ($context_is_admin && $admin_bypass_access_admin || !$context_is_admin && $admin_bypass_access_front) {
      $bypass_access_check = TRUE;
    }
  }
  else {
    if ($context_is_admin && $this->account
      ->hasPermission('bypass menu_per_role access admin') || !$context_is_admin && $this->account
      ->hasPermission('bypass menu_per_role access front')) {
      $bypass_access_check = TRUE;
    }
  }
  return $bypass_access_check;
}