Enabling and prioritising interface text language detection of account administration pages causes RouteMatch to be Null in some cases

Created on 18 February 2022, almost 3 years ago
Updated 21 October 2024, 2 months ago

Problem/Motivation

After enabling the 'Account administration pages' setting at /admin/config/regional/language/detection,
there are cases where \Drupal::routeMatch()/ return a NullRouteMatch

Steps to reproduce

At this point, if you debug the function of the class
ProductVariationAccessControlHandler::checkCreateAccess()

You'll see that the variable $product = \Drupal::routeMatch()->getParameter('commerce_product');
Is null, because the RouteMatch itself is a NullRouteMatch.

This doesn't happen if the 'Account administration pages' isn't active, or it has less priority of the URL in the 'Interface text language detection' option list. However, the latter case ins't a good solution: if the URL detection has priority over the 'Account administration pages` the latter has pretty much no use.

I have used the Commerce issue in the explanation on how reproduce because it is a real case where it is happening, but I believe it could happen in other situations too.

🐛 Bug report
Status

Needs review

Version

11.0 🔥

Component

language system

Created by

🇮🇹Italy Giuseppe87

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇪🇸Spain akalam

    We've found a similar issue when working with the groups module. We've created a custom group_permission_calculator service, similar to the new Access Policy API but for groups. In that service, we are trying to use the \Drupal::routeMatch()->getParameter('group_content'), and that method is returning null when accessing to group_content pages. While debuging, we've found that the call to the access check comes from the following function:

    \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUserAdmin::isAdminPath

    This is the problematic code:

          $route_match = $this->stackedRouteMatch->getRouteMatchFromRequest($request);
          if ($route_match && !$route_object = $route_match->getRouteObject()) {
            try {
              // Some inbound path processors make changes to the request. Make a
              // copy as we're not actually routing the request so we do not want to
              // make changes.
              $cloned_request = clone $request;
              // Process the path as an inbound path. This will remove any language
              // prefixes and other path components that inbound processing would
              // clear out, so we can attempt to load the route clearly.
              $path = $this->pathProcessorManager->processInbound(urldecode(rtrim($cloned_request->getPathInfo(), '/')), $cloned_request);
              $attributes = $this->router->match($path);
    

    Replacing the "router" service by "router.no_access_checks" is solving the issue, and seems ok in order to check if the current route is an admin route or not. The change can provide also a beneficial side-effect in terms of performance.
    I'm adding a patch with that change and linking a couple of issues that might be related.

  • 🇺🇸United States smustgrave

    Thanks for reporting.

    So fixes should be submitted via MRs.

    Also could we get a test case showing the problem.

  • First commit to issue fork.
  • Pipeline finished with Canceled
    2 months ago
    Total: 585s
    #319662
  • Pipeline finished with Failed
    2 months ago
    Total: 98s
    #319671
  • Pipeline finished with Success
    2 months ago
    Total: 2028s
    #319673
  • Pipeline finished with Failed
    2 months ago
    Total: 639s
    #320062
Production build 0.71.5 2024