New answers tagged

1

The menu per role module does exactly like you want. It allows you to set a menu link to only be visible by a specific role, in this case anonymous users.


1

To expand on @skorzh answer and reply to the comment from @Matt, if you want to nest a menu item inside another you have to get the parent id and set it as 'parent'. As an example this code nests the item inside the top level using the variable $top_level below. $my_menu = \Drupal::entityTypeManager()->getStorage('menu_link_content') ->...


0

May you can use hooks: /** * Implements hook_preprocess_HOOK() for menu.html.twig. */ function mytheme_preprocess_menu(&$variables) { if ($variables['menu_name'] == 'main') { if (!isset($variables['attributes']['class'])) { $variables['attributes']['class'] = []; } $variables['attributes']['class'] = array_merge($variables['...


1

@Weri, I would avoid doing that, having just implemeted your suggestion and spent the best part of a day trying to fix another issue. The query alter you suggest also affects entiry reference when linking paragraphs to nodes. A node I was woking on had 80+ paragraph item before I added the alter. Once added I was unable to save the node. Removing/Commenting ...


1

Set onlyEnabledLinks() on the menu tree parameters: $parameters = new MenuTreeParameters(); $parameters->onlyEnabledLinks(); $tree = \Drupal::menuTree()->load('main', $parameters);


0

For what you are trying to achieve I found out you can use the Menu Manipulator module. This module initially aimed to fix [Issue] Untranslated menu items are displayed in menus. Notes This module initially aims to fix this core issue with unstranslated menu items. Having this module installed only menu items that are available in the current ...


Top 50 recent answers are included