Questions tagged as ['navigation']
I am currently displaying the Menu "description" underneath each link using menu.html.twig. by doing this:
{% if item.original_link.getDescription %}
<span class="navigation__link-description">{{ item.original_link.getDescription() }}</span>
{% endif %}
The issue is that it's not anchored with the URL due to it being outside {{ link(item.title, item.url) }}
. Does anyone know what I ne ...

I need a background image per menu item. For this I'm using menu_item_extras. I added an image field to menu items. This field I'd like to use in page.html.twig.
How can I use this field in this template?

I have the following menu in my system.
The parent menu-link connects to a node whose ID is 58. All the sub menu-links have a parent ID equal to 58.
I need to find the main and the sub-menus using 58, but I have been unsuccessful at locating the a table that contains that information.
How can I list the nodes that share a particular menu ID?
If a menu item has a submenu and I specify the hash symbol (#) in the Link field of such parent menu item in the admin panel, I receive empty url at the frontend and therefore if click by such link, I follow to the homepage.
Even if I use in my menu--main.html.twig
template the code like
{% set menu_item_url = item.url %}
{% if menu_item_url == '' %}
{% set menu_item_url = '#' %}
{% endif %}
<a ...
I use this simple template (menu--main.html.twig) to render the main menu I created.
<ul>
{% for item in items %}
<li>
{{ link(item.title, item.url) }}
{% if item.below is not empty %}
<div class='submenu'>
{% for subitem in item.below %}
{{ link(subitem.title, subitem.url) }}
{% endfor %}
...
For our unified Drupal platform, we require all of our sites main menu items to be a page and any sub-pages to show a path following the parent menu item. So if "About Us" (with a path of /about-us) is a top level menu item, it must be a page. And the page "History" under that will have a path of /about-us/history. "About Us" cannot be a <nolink>
with History as a child. How can I prevent users ...
How do I add the core user module links such as My account and Log out to another menu?
We have an annual reporting sites that contains approximately 200 nodes each year. When the next year's reports are complete, all of the current year's nodes move to a path like /archives/fy2020/*
. Not only do their paths change, but the menu items change as well to 1) create a new entry year 2) move menu items to the new entry year as the parent.
I am looking at what type of batch process I can used to ...
In Drupal 9, I need the ability to prepend Font Awesome icons to menu links.
I have attached Font Awesome 5 JS and CSS assets to my theme via *.libraries.yml
.
If I open a menu link in the DOM inspector and edit the markup of a link from this:
<ul class="clearfix nav">
<li class="nav-item">
<a href="#comments" class="nav-link nav-link-comments">Comments</a>
</li>
&l ...
I need to programmatically load the links that are generated from my_module.links.task.yml on another page.
My exact use case is that I have a set of links that are shown when viewing my node page. The links will be shown and hidden based on the current user's access and the access control is handled through the options in the my_module.routing.yml file.
I need to create a separate page that displa ...
Good morning all,
Today I would like to ask a simple question about the menus. How do you make a clean sidebar that takes up the entire length of the page? In general, the themes offer only natively horizontal menus that occupy the entire width.
To have a sidebar, you must put the menu in a block side position and make the necessary adjustments with CSS?
I need to receive (for example by menu machine name) and operate menu items data to use it in Drupal Twig template like:
<ul>
{% for item in items %}
<li><a href="{{ item.url }}">{{ item.title }}</a></li>
{% endfor %}
</ul>
But I can't find an information on how to do that.
The only thing I've found is like
{% import _self as menus %}
{{ menus.menu_links(items ...
I have a module-generated menu (using yaml file) with 5 menu items. My requirements don't allow me to restrict menu item visibility by role because roles can be dynamically added. So I have to do this using permissions only.
What I've tried
(1) Restricting menu item access using route permissions - this shows a page forbidden but still allows the restricted menu item to be visible
Please see my actual fi ...

I am currently searching for a possibility to set an action to "inactive" depending on something.
I have found the hook_menu_local_actions_alter(&$local_actions)
, but do not know how I could use it to set a task to disabled/inactive.
What I have tried for now is:
function my_module_menu_local_actions_alter(&$local_actions) {
$local_actions['entity.my_module.add_form']['options']['attribute ...
I installed the "Profile" module on my "Drupal 9" website. When I create a profile type, the module automatically creates a tab in the user account for each profile type.
For my profile type "projects" the user account tab displays the page for this profile type, with this path :
/user/ID/project/list
Here is the view added by the module :
Here are the tabs created in the user account :
I created ...
I have been trying to translate menu items programmatically but upon saving it just adds the english field value to all my translations. Below is the code I am trying to execute:
if ($entity->hasTranslation($language->getId())) {
//For update
$entity->removeTranslation($language->getId());
}
try {
$entity->addTranslation($language->getId(), ['title' => ...