Problem/Motivation

The MenuLinkContentAccessControlHandler currently requires the "administer menu" permission for all "view" operations on menu link content entities. This overly restrictive access control prevents menu links from being accessible through REST, JSON:API, and GraphQL APIs, as well as entity reference fields, unless users have administrative permissions.

This creates a significant limitation for headless and decoupled Drupal architectures where frontend applications need to access menu structures.

Steps to reproduce

1. Create a menu link content entity that links to a node or other accessible resource
2. Attempt to access the menu link via JSON:API
3. Observe that access is denied

Proposed resolution

Modify the MenuLinkContentAccessControlHandler's `checkAccess()` method to implement more granular view access logic:

1. Continue allowing view access for users with "administer menu" permission
2. For internal links (routed URLs), check if the user has access to the linked route using the Access Manager. If they can access the destination, grant view access to the menu link
3. For external links, grant view access since there's no way to verify destination access
4. Return a neutral access result if none of the above conditions are met

This approach ensures that menu link visibility aligns with the visibility of their destinations, making menu structures accessible via APIs while maintaining appropriate security boundaries.

Remaining tasks

User interface changes

Introduced terminology

API changes

The MenuLinkContentAccessControlHandler's access logic changes, but the API signature remains the same. This is a behavior change that makes menu link content entities accessible via REST, JSON:API, and GraphQL based on destination access rather than requiring administrative permissions.

Cache tags are now properly added to access results, including dependencies on the linked entities (e.g., `user:1` for a link to user/1).

Data model changes

Release notes snippet

Menu link content entities can now be accessed via REST, JSON:API, and GraphQL APIs based on a user's ability to access the linked destination, rather than requiring the "administer menu" permission. This improves support for headless and decoupled architectures while maintaining appropriate access controls.

CommentFileSizeAuthor
#114 2915792-menulinkcontentaccesscontrolhandler-does-not-114.patch6.39 KBmorgothz
#102 2915792-menulinkcontentaccesscontrolhandler-does-not-101.patch6.68 KBgrevil
#101 2915792-nr-bot.txt3.68 KBneeds-review-queue-bot
#100 2915792-MR-339-100.patch.diff6.39 KBanybody
#95 2915792-MR339-95.patch5.42 KBanybody
#89 2915792-no-access-check-v10.0.9.patch1.14 KBauseidon986
#88 2915792-v10.0.9.patch2.29 KBauseidon986
#85 2915792-allow-base-links.patch2.19 KBmarekgti
#82 2915792-82.patch1.94 KBpbouchereau
#80 2915792-80.patch1.94 KB_utsavsharma
#80 interdiff_78-80.txt720 bytes_utsavsharma
#78 menu-link-content-disallow-veiw-whtout-admin-perm-2915792-78.patch1.94 KBartem_kondra
#47 2915792-47.patch4.83 KBbunty badgujar
#46 2915792-46.patch4.79 KBbunty badgujar
#40 2915792-40.patch5.09 KBwim leers
#40 interdiff.txt3.25 KBwim leers
#36 2915792-36.patch1.77 KBjustafish
#31 menu_link_content-view-permissions-2915792-31.patch2.6 KBmusa.thomas
#18 menu_link_content-view-permissions-2915792-17.patch3.18 KBgargsuchi
#17 menu_link_content-view-permissions-2915792-17.patch4.82 KBgargsuchi
#16 menu_link_content-view-permissions-2915792-16.patch1006 bytesharrrrrrr
#3 menu_link_content-view-permissions-2915792.patch1.75 KBcachesclay
#8 interdiff-2915792-03-08.txt1.81 KBvoleger
#8 menu_link_content-view-permissions-2915792-08.patch382 bytesvoleger
#11 interdiff-2915792-03-11.txt1.91 KBvoleger
#11 menu_link_content-view-permissions-2915792-11.patch2.16 KBvoleger
#12 interdiff-2915792-11-12.txt578 bytesozin
#12 menu_link_content-view-permissions-2915792-12.patch2.39 KBozin

Issue fork drupal-2915792

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

cachesclay created an issue. See original summary.

cachesclay’s picture

Issue summary: View changes
cachesclay’s picture

voleger’s picture

Category: Feature request » Bug report
Status: Active » Needs review
Issue tags: +Contributed project blocker

Our module blocked by this issue #2925283: Additional fields in menu items not visible for anonymous users
It disallows view menu_link_content fields for the anonymous user.

Status: Needs review » Needs work

The last submitted patch, 3: menu_link_content-view-permissions-2915792.patch, failed testing. View results

kir lazur’s picture

Patch from #3 helps to solve issue #2925283: New fields visibility and access

mike.davis’s picture

Patch #3 worked for me to enable the menu links to be available for anonymous user when using JSON API.

Just need to update the tests for this :).

voleger’s picture

Version: 8.4.x-dev » 8.5.x-dev
StatusFileSize
new1.81 KB
new382 bytes
voleger’s picture

Oops)
Late night patches) I`ll upload correct patches with some changes ASAP.

voleger’s picture

voleger’s picture

ozin’s picture

StatusFileSize
new2.39 KB
new578 bytes

Added creation access check. Since we do not use the "administer menu" permission for view menu item, we will need rewrite Drupal\Tests\rest\Functional\EntityResource\MenuLinkContent\MenuLinkContentResourceTestBase test.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

berdir’s picture

I asked similar questions about block_content entities in core. How would you even access a menu link exactly? IMHO, what would be more useful is a REST representation of all the links in a menu or maybe a menu block.

voleger’s picture

harrrrrrr’s picture

This patch allows access for all menu items without access checks.

It's usefull when jsonapi is used in more complex setups. Domain access in our case & cross domain links don't work with the access restrictions.

gargsuchi’s picture

Edit - removing.

gargsuchi’s picture

StatusFileSize
new3.18 KB

EDIT: Please ignore the patch attached.

The same bug happens when we use JSONAPI and include menu fields. The menu fields which are included start giving out 403 error.
The patch in #3 does not help in such a scenario.

The problem is this code in MenuAccessControlHandler

protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    // There are no restrictions on viewing the label of a date format.
    if ($operation === 'view label') {
      return AccessResult::allowed();
    }
    // Locked menus could not be deleted.
    elseif ($operation === 'delete') {
      if ($entity->isLocked()) {
        return AccessResult::forbidden('The Menu config entity is locked.')->addCacheableDependency($entity);
      }
      else {
        return parent::checkAccess($entity, $operation, $account)->addCacheableDependency($entity);
      }
    }

    return parent::checkAccess($entity, $operation, $account);
  }
gargsuchi’s picture

wim leers’s picture

Title: Menu content is not accessible via jsonapi » MenuLinkContentAccessControlHandler does not allow "view" access without admin permission, making these entities inaccessible via REST, JSON API and GraphQL
Category: Bug report » Task
Issue tags: +API-First Initiative

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

audriusb’s picture

#18 works without menu name filter. Once &filter[menu_name]=main is added, menu disappears for anonymous user.

audriusb’s picture

Got it working. some background can be found in #3025372

the actual fix is to create hook_jsonapi_entity_filter_access that allows access. Otherwise by default it is checking wether user has admin permission.

function hook_jsonapi_entity_filter_access(EntityTypeInterface $entity_type, AccountInterface $account) {
  if ('menu_link_content' == $entity_type->id()) {
    return ([
      JSONAPI_FILTER_AMONG_ALL => AccessResult::allowed()
    ]);
  }
}
wim leers’s picture

berdir’s picture

I still think that exposing this API directly for read access like that is the wrong approach if what you want to see/display is a menu tree.

IMHO, there should be a dedicated API that exposes the menu tree API, similar to how SystemMenuBlock::build() does it. While it might not be that common in decoupled scenarios, only getting menu_link_content entities means you don't get views and module provided menu links, and you also don't support additional types of menu links in contrib, like https://www.drupal.org/project/menu_link and https://www.drupal.org/project/menu_link_config.

Then we could also properly process trees and expose the same options as the block has to get the full hierarchy or just a certain level/depth.. I assume right now people are re-implementing that in their clients?

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

voleger’s picture

Dizzydaizys’s picture

Assigned: Unassigned » Dizzydaizys
Dizzydaizys’s picture

musa.thomas’s picture

Still get the problem when use into graphQL

musa.thomas’s picture

The patch #12 work but not compatible with 8.7

wim leers’s picture

Priority: Normal » Major
Related issues: +#3067627: API users cannot access menu links

This was reported again and appears to be a JS Admin UI Initiative blocker: #3067627: API users cannot access menu links.

Bumping priority.

berdir’s picture

I don't think anyone replied about my concerns yet? :)

What about editing non-menu_link_content entities? That needs to be possible too. And view is tied to edit, so if you can edit, you can also view them, what exactly is missing for the Admin UI use case?

wim leers’s picture

#33: sorry, I didn't re-read the issue!

#25: You're absolutely right. I share this concern. I said exactly that in Drupal Slack when @justafish raised her original bug report (#3066768: `parent` field on MenuLinkContent entities uses `string` field type, which is semantically wrong and burdens HTTP API clients — I included it in the issue summary there too). That being said, I do think it's valid to be able to list and query and update just menu_link_content entities too. Some sites only have those. That'd at least solve part of the problem.

justafish’s picture

> I do think it's valid to be able to list and query and update just menu_link_content entities too. Some sites only have those. That'd at least solve part of the problem

This is exactly the use case I have currently, and being able to just list and query those entities totally solves the problem for us

justafish’s picture

Status: Needs work » Needs review
StatusFileSize
new1.77 KB

Accessing the menu entity as an anonymous user seems to work fine already, so this was sufficient to allow me to access menu links.

wim leers’s picture

#35: Thanks, that' super helpful to know 👍

#36: This patch looks very different than previous iterations. It sounds like you extracted just the parts that you need?

Status: Needs review » Needs work

The last submitted patch, 36: 2915792-36.patch, failed testing. View results

justafish’s picture

@Wim Leers - It's #18 with the code for viewing menu entities removed (as this already works), and a documentation update.

wim leers’s picture

Assigned: Dizzydaizys » Unassigned
Status: Needs work » Needs review
StatusFileSize
new3.25 KB
new5.09 KB

I was confused why you started from #18, but then I started looking at the patches and #31 surprisingly used #12 instead of #18. #18 in turn confusingly says to please ignore it. The patch in #16 is outright dangerous. So #18 does seem like the most logical choice now 😀

Let's continue iterating on #18 with the goal to land it in Drupal core 🙏

+++ b/core/modules/menu_link_content/src/MenuLinkContentAccessControlHandler.php
@@ -50,9 +50,21 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
+        // If menu link is internal, and user has access, grant view access to
+        // the menu link.
...
+        // Grant view access to external links.

Is this truly acceptable? Seeing the target URI or target route is one thing, that is probably fine indeed, but menu links also contain other information such as description. I think pretty much always that information will not be sensitive. But I don't know that we can assume that that will always be true.

I think a safer option may be to add a permission?

ON FURTHER INSPECTION I noticed:

    $fields['description'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Description'))
      ->setDescription(t('Shown when hovering over the menu link.'))

So never mind my concern above :)


That's why I started contributing to the patch to help fix the failing tests :)

Status: Needs review » Needs work

The last submitted patch, 40: 2915792-40.patch, failed testing. View results

justafish’s picture

Looks like #36 doesn't actually get the job done sadly - filters don't work for anonymous users

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

remediosaraya’s picture

I wonder if there is any update on this issue related to the menu childs and graphql?

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

bunty badgujar’s picture

Status: Needs work » Needs review
StatusFileSize
new4.79 KB

patch #40 is no longer valid for 9.x. Re-rolling #40

bunty badgujar’s picture

StatusFileSize
new4.83 KB

Ignore #46

Status: Needs review » Needs work

The last submitted patch, 47: 2915792-47.patch, failed testing. View results

oscarino’s picture

Without using any of the patches that alter core files, I took the logic used in one of the patches to make this work using only drupal hooks. Assuming `yourmodule` is a custom module, place these codes inside `yourmodule.module` file:

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Session\AccountInterface;

/**
 * Implements hook_ENTITY_TYPE_access().
 */
function yourmodule_menu_link_content_access(EntityInterface $entity, $operation, AccountInterface $account) {
  if ($operation == 'view') {
    // Check whether user has permission to access menu.
    if ($account->hasPermission('administer menu')) {
      return AccessResult::allowed()
        ->cachePerPermissions()
        ->addCacheableDependency($entity);
    }
    // If menu link is internal, and user has access, grant view access to the menu link.
    if (($url_object = $entity->getUrlObject()) && ($url_object->isRouted())) {
      $link_access = \Drupal::accessManager()->checkNamedRoute($url_object->getRouteName(), $url_object->getRouteParameters(), $account, TRUE);
      if ($link_access->isAllowed()) {
        return AccessResult::allowed()
          ->cachePerPermissions()
          ->addCacheableDependency($entity);
      }
    }
    // Grant view access to external links.
    elseif ($url_object->isExternal()) {
      return AccessResult::allowed()
        ->cachePerPermissions()
        ->addCacheableDependency($entity);
    }
  }

  return AccessResult::neutral();
}

/**
 * Implements hook_jsonapi_ENTITY_TYPE_filter_access() for 'menu_link_content'.
 */
function yourmodule_jsonapi_menu_link_content_filter_access(EntityTypeInterface $entity_type, AccountInterface $account) {
  return ([
    JSONAPI_FILTER_AMONG_ALL => AccessResult::allowed(),
  ]);
}

That worked for me. You have to override menu_link_content access and then allow user to access the menu_link_content json endpoint.

justafish’s picture

osopolar’s picture

Can this be still fixed in core, as it seems to be a "new feature" which changes current behavior? Maybe a new permission like "view menu link content" could be introduced to ensure backward compatibility.

The workaround from oscarino in #49 works well for for me to access menu items with JSON:API without granting "administer menu" permission to the API consumer. So if this can't be fixed in core, it might be done by a tiny contrib module.

borisson_’s picture

We've been testing #47 on a project and that fixes getting menu items.

+++ b/core/modules/menu_link_content/src/MenuLinkContentAccessControlHandler.php
@@ -50,9 +50,27 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
+        if (($url_object = $entity->getUrlObject()) && ($url_object->isRouted())) {
+          $link_access = $this->accessManager->checkNamedRoute($url_object->getRouteName(), $url_object->getRouteParameters(), $account, TRUE);

This should probably be rewrapped to be < 80 cols wide?

It looks like the remaining test-failure is because of caching, so that still needs to be fixed,

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Waldoswndrwrld’s picture

I'm also adding a reference to the GraphQL Issue.

kentr’s picture

#47 works on core 8.9.13

honza pobořil’s picture

#47 works for GraphQL and menu_item_extras in Drupal 8.9.13

voleger’s picture

Rerolled #47
Weird, but Drupal\Tests\jsonapi\Functional\MenuLinkContentTest::testRelationships test successfully passed locally.

voleger’s picture

Status: Needs work » Needs review

Addressed #52 and Drupal\Tests\jsonapi\Functional\MenuLinkContentTest::testRelationships test is passing now.

hhvardan’s picture

Any suggestions on how to fix this for D9 and GraphQL?

voleger’s picture

#60 Hi @hhvardan!
You can use https://git.drupalcode.org/project/drupal/-/merge_requests/339.patch as the patch for your drupal/core project dependency.

hhvardan’s picture

Hi @voleger,
I've applied patch and I'm still not able to query menu links as an anonymous user without "Administer menus and menu links" permission (the result is NULL).

askibinski’s picture

Regarding Graphql: like @hhvardan mentioned the patches in this issue won't help you because in that case the problem is not in the menu link content entity access checking, but in the menu entity access check. Because in graphql we typically do an entity load for the menu config entity, and then retrieve the items. etc.

But when loading the menu entity, MenuAccessControlHandler kicks in and will also deny access because of the admin permission needed.

I'm not aware of a contrib module which fixes this, but it is pretty easy to implement if you have for instance a set of defined menu's which are public. In that case you can use hook_entity_type_build to override the MenuAccessControlHandler to allow the view operation for a certain set of menu ID's.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

extect’s picture

Thanks @voleger et al for the work on this. The MR solved an issue for me that caused problems with the menu_item_extras module: #3178103: Custom block inside menu item not visible for anonymous

dawitti’s picture

The patch from #61 fixed the permissions issue with menu_item_extras for me too. Thanks @voleger!

hctom’s picture

Using the issue fork MR as patch fixes missing paragraphs for anonymous users when applying them via menu_item_extras in menu items.

daffie’s picture

Status: Needs review » Needs work

@voleger: The fix looks good, but I am missing the testing for all the added access possibilities. Could you add one or two @dataProvider methods, so that all access possibilities get testing.

larowlan’s picture

Issue tags: +#pnx-sprint

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

ccooksey’s picture

I'm having the same issue as #42. I can get JSON data for an anonymous user, but when I try to filter the data it returns nothing. The filter does work when I'm logged in as an administrator. Here's the filter I used: /jsonapi/menu_link_content/main?filter[id]=f7d367ef-f0fb-4d8e-96e6-1fca17f20224

Was this issue addressed in the patch?

jonnyeom’s picture

I havent been able to go deep into what is causing it but the patch in MR #339 is still giving me leaked metadata issues.
The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early.
Somewhere in this process, ->render() is being called without the cache metadata.

As a result, the jsonapi endpoint returns a 500.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dalemoore’s picture

I just ran into this issue while attempting to build a mega menu with Layout Builder following this guide with Menu Item Extras. The patch by @voleger seems to fix it for Menu Item Extras, not sure if it fixes it for all the other cases having problems.

timfletcher’s picture

I tried the patch from #61 and also encountered the 500 error when attempting to load the /jsonapi/menu/items/. The logged error was:
The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

alexander.levitsky’s picture

Hello @voleger,

Thank you for preparing this patch.

This works perfectly but unfortunately, it doesn't cover all cases. At least I found the one that doesn't work.

The issue exists in the second condition:

// If menu link is internal, and user has access, grant view access to the menu link.
    if (($url_object = $entity->getUrlObject()) && ($url_object->isRouted())) {

How to reproduce:
1. Create the node and generate automatic alias for the node. (for example, "/test-node-alias")
2. Create the menu item and use the internal path (not autocomplete) - "/test-node-alias"
3. Update the node title or make another action that will update the alias automatically. After this change, the path alias should be changed automatically and an automatic redirect should be generated.

Result: Admins can view the menu link, but anonymous users cannot since the condition $url_object->isRouted() return false.

artem_kondra’s picture

re-roll to work with 9.4.9

_utsavsharma’s picture

Status: Needs work » Needs review
_utsavsharma’s picture

StatusFileSize
new720 bytes
new1.94 KB

Fixed CCF for #78.
Please review.

voleger’s picture

Status: Needs review » Needs work

Rebased against 10.1.x branch. Needs work for #77

pbouchereau’s picture

StatusFileSize
new1.94 KB

Rerolled patch #80.

pbouchereau’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 82: 2915792-82.patch, failed testing. View results

marekgti’s picture

StatusFileSize
new2.19 KB

Modified #82 patch to allow unrouted links that starts with "/"

lendude’s picture

Title: MenuLinkContentAccessControlHandler does not allow "view" access without admin permission, making these entities inaccessible via REST, JSON API and GraphQL » MenuLinkContentAccessControlHandler does not allow "view" access without admin permission, making these entities inaccessible via REST, JSON API and GraphQL and entity reference fields

Closed #2607978: Custom menu item entity reference is not accessible to anonymous user as a duplicate of this. Discussed with @catch in #bugsmash and the possible problems with entity references should probably be handled here too.

auseidon986’s picture

Patch #85 is working on Drupal 10.0.9.

auseidon986’s picture

StatusFileSize
new2.29 KB

Attached file is broken one, please ignore it.

auseidon986’s picture

StatusFileSize
new1.14 KB

Attached file is broken one, please ignore it.

auseidon986’s picture

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

tim-diels’s picture

@Lendude regarding "Discussed with @catch in #bugsmash and the possible problems with entity references should probably be handled here too." ... Could you give some more info on what needs to be done to get this issue moving again?

anybody’s picture

@Lendude & @Voleger, we just came to this issue from here: #2925283: Additional fields in menu items not visible for anonymous users

TL;DR: Due to this, entity reference (revision) contents are not visible for guests within the Menu (example: Mega Menu implementation using Paragraphs). Workaround: Use paragraphs_type_permissions submodule, which seems to override this using hook_ENTITY_TYPE_permission()

Still we'd like to help fixing this in core, so we can remove the workaround.

You have both invested a lot of time here and I think you're aware of what has to be done to finish this. What ca we do?
We can reroll the MR against 11.x and 10.3.x but then we should try to finish it and hot have it around for years again... any feedback?

The MR still seems good, a clear improvement and has a lot of positive feedback.

anybody’s picture

Here's the current state of the MR339 which still works fine against 10.2.x, 10.3.x and eventually 11.x (haven't tried). Great work @voleger!

anybody’s picture

StatusFileSize
new5.42 KB
voleger’s picture

rest and json_api integration tests are failing

bbrala’s picture

Test are failing because the new link to user/1 is missing in the menu tests. So that should be a very easy fix.

See this link for all tests that are failing.

grevil’s picture

Not as simple as it seems. The expected cache tags are invalid, since we are swapping the "https://nl.wikipedia.org/wiki/Llama" link with a cacheable internal link to user:1. We can implement a dirty workaround and manually prepend the new cache to "getExpectedCacheTags()", but then the test will just throw an error later on.

To be honest, the current test changes generally seem really rushed. Simply replacing a remote link string with an internal link inside already existing tests / test bases without changing anything else just doesn't feel right. It also looks like we removed testing for external links entirely?

I'd say we revert the current test changes and create dedicated tests for internal menu links (json and rest) additionally to the already existing external link tests. Only problem being, that the test structure seems quite complex, so this will probably need quite a bit of work...

Really unsure about this. Does anybody else have an idea? Maybe there is a super simple way to test this, and we only need to add a quick test without changing any existing tests / test bases?

grevil’s picture

I reverted the test changes and created a new test class inside the jsonapi space. Unsure, whether to create a REST test class as well. But I don't think we should adjust the rest test base, how we did it in "MenuLinkContentResourceTestBase.php" originally, which I reverted here: https://git.drupalcode.org/project/drupal/-/merge_requests/339/diffs?com....

Unfortunately, now the old "MenuLinkContentTest" fails. Here, it expects a 403 status code, but it actually receives an unexpected 200 status code. This might show, that the current MR needs some refactoring? I am not sure. These tests are highly complex with many dependencies.

anybody’s picture

Status: Needs work » Needs review
StatusFileSize
new6.39 KB

Attached Drupal 11.1 compatible patch. Would still be great, if someone could finish the great work done here already to get this fixed. Any hero present to move this over the finish line?

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new3.68 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

grevil’s picture

Alright, that should be it. Test is still failing, so leaving this at "Needs work" for now.

Current MR as patch attached.

grevil’s picture

Status: Needs work » Needs review
Issue tags: +Needs subsystem maintainer review

Maybe we could get a subsystem maintainer to have a look at the tests, since nobody dares to do the final refinement and this is open for a while now?

bbrala’s picture

I'll try and dive into this sometime soon.

One thing that I did notice, there were some conceirns in #77, are those valid or handled?

smustgrave’s picture

Status: Needs review » Needs work

Issue summary should be complete, helps reviewer and sub-maintainers quickly understand.

lbesenyei’s picture

#102 works for our project.

grevil’s picture

Issue summary: View changes
grevil’s picture

Status: Needs work » Needs review

I updated the issue summary. None of the tests fail, but the pipeline still says "failed" no idea why. Setting back to "Needs review".

grevil’s picture

bbrala’s picture

Status: Needs review » Needs work

It needs a rebase, it has conflicts, so cannot do it in the interface :)

alexpott made their first commit to this issue’s fork.

alexpott’s picture

One thing I'm wondering is whether this issue still has relevance given the decoupled menu support already in core - see #3227824: Move the linkset functionality from the decoupled menus contributed module to core's system module

alexpott’s picture

Answering #112 for myself - in the case of my client project they are accessing media fields on the menu link content entity and that's not provided by the linkset functionality.

morgothz’s picture

Re-rerolled patch to cleanly apply in newer core version

anybody’s picture

@alexpott RE #113: Yes it's still really relevant - our case are menu items with paragraphs (for mega menu) which can't be rendered for anonymous users without this patch. See #2925283: Additional fields in menu items not visible for anonymous users

We'll rebase this one, but would be really great to finish this then?

grevil’s picture

Status: Needs work » Needs review

Alright, rebased should be good again.

anybody’s picture

grevil’s picture

Status: Needs review » Needs work

Tests fail.

grevil’s picture

Hm unsure why the tests fail. The tests expect a 200er status code, but receive a 302 (redirect):


1) Drupal\Tests\jsonapi\Functional\MenuLinkContentTest::testGetIndividual
NULL
Failed asserting that 302 is identical to 200.

Weird, the test results are completely different online, my apologies.

grevil’s picture

Hm, no idea, how to properly fix the test issues. And I can't really wait for the remote test output after every single change. Maybe someone else has more luck fixing it.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

swirt’s picture

That patch from this merge request is odd. It contains a ton of code that is jibberish
https://git.drupalcode.org/project/drupal/-/merge_requests/339.patch
It looks like it is coming from a gzip file that got added and then removed
/core/modules/system/tests/fixtures/update/drupal-9.3.0.bare.standard.php.gz
In this commit, which seems completely unrelated https://git.drupalcode.org/project/drupal/-/merge_requests/339/diffs?com...

If any of the maintainers have the ability to do an interactive rebase on this and remove the noise, it would be good.

grevil’s picture

@voleger can you adjust the MR target to target main?

@swirt never seen using ".patch" at the end of a merge_request link. The plain diff looks fine to me though: https://git.drupalcode.org/project/drupal/-/merge_requests/339.diff

voleger’s picture

#123: done