function SystemAdminMenuBlockAccessCheck::access

Same name in other branches
  1. 10 core/modules/system/src/Access/SystemAdminMenuBlockAccessCheck.php \Drupal\system\Access\SystemAdminMenuBlockAccessCheck::access()

Checks access.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The cron key.

\Drupal\Core\Session\AccountInterface $account: The current user.

Return value

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

File

core/modules/system/src/Access/SystemAdminMenuBlockAccessCheck.php, line 56

Class

SystemAdminMenuBlockAccessCheck
Access check for routes implementing _access_admin_menu_block_page.

Namespace

Drupal\system\Access

Code

public function access(RouteMatchInterface $route_match, AccountInterface $account) : AccessResultInterface {
    $parameters = $route_match->getParameters()
        ->all();
    $route = $route_match->getRouteObject();
    // Load links in the 'admin' menu matching this route. First, try to find
    // the menu link using all specified parameters.
    $links = $this->menuLinkManager
        ->loadLinksByRoute($route_match->getRouteName(), $parameters, 'admin');
    // If the menu link was not found, try finding it without the parameters
    // that match the route defaults. Depending on whether the parameter is
    // specified in the menu item with a value matching the default, or not
    // specified at all, will change how it is stored in the menu_tree table. In
    // both cases the route match parameters will always include the default
    // parameters. This fallback method of finding the menu item is needed so
    // that menu items will work in either case.
    // @todo Remove this fallback in https://drupal.org/i/3359511.
    if (empty($links)) {
        $parameters_without_defaults = array_filter($parameters, fn($key) => !$route->hasDefault($key) || $route->getDefault($key) !== $parameters[$key], ARRAY_FILTER_USE_KEY);
        $links = $this->menuLinkManager
            ->loadLinksByRoute($route_match->getRouteName(), $parameters_without_defaults, 'admin');
    }
    if (empty($links)) {
        // If we did not find a link then we have no opinion on access.
        return AccessResult::neutral();
    }
    return $this->hasAccessToChildMenuItems(reset($links), $account)
        ->cachePerPermissions();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.