Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I created a custom block type with an entity renference field to custom menu items. After that, I created a block of this type with some references to existing menu items.
The problem is, anonymous users does not see this block, while uid=1 does see it. Caches cleared in every possible way.
Comments
Comment #2
dawehnerI'd wondering which URL did you placed inside there? Could this link itself be maybe not accessible for the anonymous user?
Comment #3
EdgarPE CreditAttribution: EdgarPE commentedThe custom menu items are in a separate menu. This menu's block is placed in the sidebar, and anonymous user can see the menu items and access the pages just fine.
Comment #4
krlucas CreditAttribution: krlucas at Genuine commentedI have this same issue. I want to render a View of Blocks with entity reference field to menu items so the blocks can act as menu flyouts. I want to use the menu item id as a data attribute on the rendered block/row.
Result: Anonymous can see and click on the menu items in the actual menu and access the destination nodes. Anonymous users can't see the entity_id of the menu items in the view.
It appears at some point, to render the entity reference, there's a check to see if the user can *edit* the referenced menu item.
Comment #10
josecastrop CreditAttribution: josecastrop commented¿Anyone knows a solution to this problem? In 8.5.3 the issue persist. Impossible to see the menu link as entity reference without administrator role.
Comment #11
matthiasm11 CreditAttribution: matthiasm11 at Randstad Digital commentedI had the same problem: menu items referenced from a node were getting a -Restricted access-.
Found out that the language of the menu item needs to be the same as the language of the node where the reference field resides.
Comment #13
blake.thompson CreditAttribution: blake.thompson at Slalom commentedJust came across this issue myself. I have a custom block type with an entity reference field for a menu link item. I'm placing the block through layout builder and that field is not rendered for anonymous users. I don't have language options for my node or my menu item, so I'm not sure how to address that.
edit: I checked and my node, block and menu link all seem to have the same langcode.
Comment #14
kitzinger CreditAttribution: kitzinger commentedRidiculously, this issue persists in 8.7.6.
When creating an entity reference field for Custom menu item, anonymous users are unable to view the referenced item.
Comment #15
bratej CreditAttribution: bratej commentedI also have this issue on 8.7.1. For this to work anonymous users would have to have the permission "System->Administer menus and menu items" set, which of course you don't want to do.
It looks like if the display type is "Entity ID" the value is not printed (no permission?). If you display the entity label it prints just fine.
My workaround in a twig template is the following:
{% set menu_id = content.field_YOURMENU_ENTITY_REFERENCE_FIELD[0]['#options']['entity'].id() %}
The menu_id gets the value of the Entity ID. I then print the menu with the Twig Tweak contributed module:
{{ drupal_menu(menu_id) }}
Not the prettiest thing in the world but it works :P.
Comment #16
kitzinger CreditAttribution: kitzinger commented@bratej - this is wrong. With the display type as label, nothing is printed for anonymous users either.
Comment #23
LendudeThis came up as a Bug Smash daily triage issue.
Discussed this with @catch and we agree that we should close this as a duplicate of #2915792: MenuLinkContentAccessControlHandler does not allow "view" access without admin permission, making these entities inaccessible via REST, JSON API and GraphQL and entity reference fields. There seems to be more activity on that issue and we should tackle the problem with entity references in the same issue.
Feel free to open this back up if you feel these are two separate issues or that there is a good reason not to solve these issues at the same time.