Menu link "Inaccessible" for anonymous users if page is archived

Created on 10 January 2024, 12 months ago

Problem/Motivation

We're seeing menu links that read "Inaccessible" for anonymous users when the page the link goes to is archived (i.e. unpublished). I've tried changing the theme, checking permissions, etc., but haven't been able to find a solution. The link shouldn't be visible to anonymous users. I've seen similar issues reported for contrib modules, but we're not using the modules that people have reported the issue for. I'm not seeing anything in the logs. It's probably something particular to our codebase, but I'm not sure how to debug it. Anybody have any helpful hints on what to be looking for? Thanks.

πŸ’¬ Support request
Status

Active

Version

9.5

Component
Menu systemΒ  β†’

Last updated about 21 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States medinasod

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

Comments & Activities

  • Issue created by @medinasod
  • This is the expected behavior when something renders an inaccessible link. Are you absolutely sure the site has no menu-related contributed modules, no custom code rendering menu links, and no related patches applied?

    You mentioned not knowing how to debug this. Here's how:

    1. Setup and start a PHP debugger.
    2. Put a breakpoint in Drupal\Core\Menu\InaccessibleMenuLink::getTitle().
    3. When execution stops at the breakpoint, observe the call stack.

    P.S. Drupal 9 reached end-of-life last year and is no longer supported.

  • πŸ‡ΊπŸ‡ΈUnited States medinasod

    Thanks for your help, @cilefen. There aren't any menu-related contrib modules, but there is a ton of custom code (it's a site I inherited). There is a menu-related custom module, but I'm not sure how it would cause this issue because it's implementing hook menu_edit_form_alter. The only patch being applied is for viewsreference, so that shouldn't be a problem. We have another Drupal 9.5 site and it doesn't have the same issue (the inaccessible links don't appear for anonymous users), but that site is built in a more standard way (less custom code). I've struggled getting xcode working with phpstorm and lando, so I was just hoping someone might have had experience with this problem and what might have fixed it for them in the past. I found this:

    // Only render accessible links.
          if ($data->access instanceof AccessResultInterface && !$data->access->isAllowed()) {
            continue;
          }
    

    in /web/core/lib/Drupal/Core/Menu/MenuLinkTree.php (line 245), so it seems like the links shouldn't be displaying.
    Thank you for the tip about debugging. I'll try to get xdebug working (fingers crossed!).

Production build 0.71.5 2024