Hi, As the name of the title.

If you add a menu item via the UI and add a link with the value "#what-we-do", this value will not show in the response when loading this menu.

I have attached an image showing the admin page where I add this value, and another image showing the response for this menu item.

Please note that this is for a decoupled website and so I am not able to add a relative link (or even an absolute url). All I need is a hash value and the decoupled website will do the rest when it receives this hash value.

Comments

hga77 created an issue. See original summary.

harcher’s picture

Issue summary: View changes
fabianderijk’s picture

Assigned: Unassigned » fabianderijk

Hmmm okay, weird. I'll take a look at it!

  • fabianderijk committed a3e0bc6 on 8.x-2.x
    Issue #3068198 by hga77: Menu link with hash value/anchor does not get...
fabianderijk’s picture

Assigned: fabianderijk » Unassigned
Status: Active » Fixed

This is now fixed in the dev version. You can enable the checkbox to add the fragment on the settings page (admin/config/services/rest_menu_items). The fragment is then added to the alias, absolute url and relative url.

ainarend’s picture

Status: Fixed » Needs work

Hey, sorry to be a party pooper, but I feel that we missed one additional Drupal feature. In our Drupal projects I have seen clients use the # in the menu link urls to create a no link menu item.

The no link menu items are used for example when the menu has 2 levels and the editors want to create a first level element that doesn't link anywhere, but allows opening the dropdown to the second level.

And in my eyes, as using # and everything that comes with it works automagically with coupled Drupal menus, i'd expect this to work for the decoupled menu as well, without any additional configuration, so in my eyes the default option for the new configuration item should be checked, not sure about BC here for existing sites).

Simplytest site showing my use case:

The site:
https://drgit.ply.st/

Main menu API response, showing that the no menu item is missing the # in alias:
https://drgit.ply.st/api/menu_items/main

  • fabianderijk committed 3f5ba61 on 8.x-2.x
    Issue #3068198 by hga77, fabianderijk, ainarend: Menu link with hash...
fabianderijk’s picture

@ainarend, I would discourage using the # for non-linking menu items. In Drupal 8 you can use route:<nolink> for that.

About the option being enabled by default, I checked this and I don't think this will cause any issues. I will however only set in in the install config yml, so it will work with new installs. Existing installs will need to enable the option manually. This is already available in the dev version of the module. Once we have more bug-fixes, new features or we don;t in about 2 weeks I will release a new stable version.

ainarend’s picture

Status: Needs work » Fixed
StatusFileSize
new78.1 KB

Of course, i forgot about the route:<nolink>. Thanks! I have nothing more to add, seems that everything else is all good.

Hopefully this will serve as sort of documentation for some one like me in the future :D I'll add a quick screenshot of the API result as well, mind that when using the nolink route there is no uri, alias or any other url related properties in the response, so that's something that people using the response should be aware of.

route nolink response

harcher’s picture

@fabianderijk, that fixed my issue, the hash value/fragment is showing now. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.