Skip to main content

Questions tagged [navigation]

Use it for questions about navigation menus and links used in a site.

Filter by
Sorted by
Tagged with
62 votes
14 answers
137k views

How to get the valid URL of a Link field from within a Twig template?

I have a Link field named field_my_link (machine name). Within a Twig template I can get the link's URL value with this: {{ node.field_my_link.uri }} If inside the Link's URL there is an external ...
Andrea's user avatar
  • 1,267
37 votes
10 answers
99k views

How do I create a link?

Say I am extending The blockBase class to create a custom block, and I am implementing the blockBuild method to create some markup for my block. Something like this: class YourModuleBlock extends ...
dbj44's user avatar
  • 4,764
27 votes
6 answers
30k views

How to add module to admin/config page?

I'm working on a module in Drupal 7. I've added a hook_menu implementation: $items['admin/config/content/mymodule'] = [ 'title' => 'MyModule', 'description' => 'Configure ...
Matt V.'s user avatar
  • 2,984
23 votes
4 answers
20k views

Non-Clickable Menu Items

In a Drupal 8 site, I want to add menu items with "no link", I was thinking that nolink is allowed but when I entered this, I got error Manually entered paths should start with /, ? or #. Is ...
Mohamed Osama Gbril's user avatar
22 votes
7 answers
14k views

How to create an EMPTY anchor-only link with l()?

I'm trying to use l() to get something like <a href='#' ...>, for ajax-calling purposes. https://stackoverflow.com/questions/1698453/drupal-creating-anchor-only-link-with-l is very close to the ...
Jim Miller's user avatar
  • 1,948
17 votes
10 answers
28k views

Add class to content field (link)

I want to add a class to the <a> tag of a field that consists of a link and text. (It's a field of type Link.) The name of the field is content.field_c_button_link. In the template file, I ...
maidi's user avatar
  • 271
17 votes
3 answers
18k views

How can I add items to the Admin Toolbar?

In Drupal 8, I want to add a menu item to the Admin Toolbar with a submenu, with different links. How can I do it?
jmzea's user avatar
  • 982
15 votes
5 answers
29k views

Programmatically create a menu

How can I programmatically create a menu? I have 3 different menus I want to create: The first menu will be placed in the top left of the header; the second menu will be placed below the first menu; ...
user8012's user avatar
  • 602
13 votes
4 answers
28k views

How do I create menu links programmatically?

I need to add some links to existing menu (or to new) programmatically in Drupal 8.
skorzh's user avatar
  • 1,474
13 votes
6 answers
5k views

How to display more than 10 items in link widget autocomplete?

This is a question about the Link module. Since with the Link module you can enter external or internal links both, we strongly rely on it. Unfortunately the number of items to be displayed from its ...
leymannx's user avatar
  • 18.3k
12 votes
4 answers
9k views

Export menu configuration [closed]

Looking for a way to export menu configuration. The Configuration management system will export the menu itself, but not the menu links configuration. I am looking for a way to put one of those mega ...
brittany_p's user avatar
11 votes
4 answers
4k views

No navigation links on 404 pages

When I visit a page that does not exist, I expect to still see the primary and secondary links as on any other page, but what I get is no navigation links in the 404 page. See also No navigation links ...
niksmac's user avatar
  • 7,692
11 votes
7 answers
19k views

How to add fields to menu items

I need to build a main menu that is a subset of the regular menu. The design team thinks it would be better for user to have only the most important links in the main menu and not have everything. ...
Guillaume Bois's user avatar
11 votes
2 answers
312 views

What is the reason behind the current menu structuring

I'm not much of a Drupal Ninja; from what I saw at http://drupal.org/node/788972, Drupal seems to have a menu structure like Joomla, in the sense that it allows menu items to be created under menu ...
saji89's user avatar
  • 211
10 votes
3 answers
21k views

How to set target="_blank" for links in CKEditor

I use CKEditor in Drupal 8. I want that every link will open in a new tab of browser. I want that the code look like this <a href="#" target="_blank">my link</a> But if I use the ...
lesley n.'s user avatar
  • 909
10 votes
4 answers
18k views

Render menu in twig template

In admin/structure/menu I created a menu. Is it possible to render this menu (with machinename: my_menu) in a twig template? Somehow like: {{ my_menu }}
meez's user avatar
  • 1,333
10 votes
6 answers
23k views

How to add a Login / Logout link in Main navigation menu?

How can I add a Login link to the "Main navigation" menu? When a user clicks on the link, it should take them to the /user/login page. Once they login, the link should change to say "Logout" instead ...
GTS Joe's user avatar
  • 331
9 votes
2 answers
12k views

How to turn a menu tree into an associative array?

I've dig into Drupal menu core to find out a way to build an associative array from a menu tree(eg,the account menu) so that I can output the data as json format. But it seems not possible to do this ...
JIA's user avatar
  • 155
9 votes
2 answers
6k views

Remove the 'read more' and 'Add new comment' links on the home page

How do you remove or modify the list of links shown after the content?
Onita's user avatar
  • 714
9 votes
2 answers
7k views

What is the equivalent of hook_translated_menu_link_alter() to alter a menu link? [duplicate]

I want to alter the menu link in Drupal 8. In Drupal 7 we can achieve this using hook_translated_menu_link_alter(). function module_translated_menu_link_alter(&$item, $map) { global $user; ...
Ajay Reddy's user avatar
  • 3,849
8 votes
5 answers
9k views

Is there a way to order views grouped fields?

I am using views to group a list of nodes by taxonomy term and display these groups as accordion headers (displayed by the views accordion module). eg: Yellow: node1 node2 Green: node1 node3 ...
autopoietic's user avatar
  • 1,672
8 votes
2 answers
10k views

How to programmatically add links to the links variable

I am using Drupal 6 and would like to modify the $links variable to include other links programmatically. I have searched high and low on Google on how to do this to no avail. Does someone know how to ...
user5013's user avatar
  • 1,497
8 votes
1 answer
9k views

Drupal 8 Permission to see Structure > Menu

Drupal 8. I want a user with a certain role to be able to see and administer menu items /admin/structure/menu/manage/main On the permissions page /admin/people/permissions I have 'Administer menus ...
heart.cooks.mind's user avatar
8 votes
2 answers
12k views

How do I alter a language item link?

I am looking to modify the default output of Drupal 8 of links in a certain situation, the language switcher. Ideally I want to be able to do that in a twig template and not have to produce a massive ...
Guillaume Bois's user avatar
8 votes
6 answers
14k views

How do I programmatically update or delete menu items?

I have seen How do I create menu links programmatically? but how do I update or delete menu items in Drupal 8? By programmatically, I mean dynamically; YAML configuration files are not going to help.
Duncanmoo's user avatar
  • 2,951
8 votes
3 answers
6k views

How do I alter the title of a menu link?

In my website, users can collect some 'points' over time. I have a top-bar menu with some links (e.g. "home", "profile", "logout"). I want to alter the menu item "profile" and add the number points ...
spacecodeur's user avatar
  • 1,339
8 votes
1 answer
2k views

What's the "Drupal" way of creating image links?

I know that the correct way to create links in Drupal is to use l($text, $path, array $options = array()). But that only allows for text links. Is there a similar function for creating images that ...
EmmyS's user avatar
  • 1,543
8 votes
2 answers
4k views

Create a new Menu in Drupal 8 programmatically

Is it possible to create a new Menu in Drupal 8 programmatically using a custom module? I am creating a custom module, and one of the requirements of the module is that it creates a new menu under ...
software_writer's user avatar
8 votes
3 answers
5k views

How to add confirmation to ajax link?

I am rendering ajax link as follows: l(t('Click here'), 'mypath', array('attributes' => array('id' => 'my-id', 'class' => array('use-ajax')))); How to display confirmation dialog before ajax ...
tomas.teicher's user avatar
8 votes
1 answer
7k views

Replacing menu items with images

I'm looking for a way to display a menu items as images (with rollover) rather than the usual text links. I found the module Menu Icons, but as the name implies, it's designed to place the icon next ...
user379468's user avatar
  • 2,520
7 votes
2 answers
12k views

Can we add the destination query parameter to a link from yml configuration?

When creating a link from yaml ie: mymodule.links.action.yml my_module.my_entity.add: route_name: node.add title: 'Add My Entity' route_parameters: node_type: 'my_entity' appears_on: ...
SwingingTom's user avatar
7 votes
5 answers
4k views

How to Rename "Request new password" link?

We want to rename the "Request new password" text on a Drupal's login page to some custom text. In the user.module file, I see that this text is hard coded if (variable_get('user_register', 1)) { ...
Ajinkya Kulkarni's user avatar
7 votes
3 answers
14k views

add a link to admin menu bar

I want to add the link to tags i.e. /admin/structure/taxonomy/tags directly to admin menu so that it appears next to "Content" link present on admin menu. How to do it?
ruby's user avatar
  • 167
7 votes
5 answers
9k views

Hiding link from anonymous users

How can I hide a particular link in the main menu from anonymous users without making the whole menu invisible?
Walker's user avatar
  • 173
7 votes
2 answers
3k views

Create a link pointing to #

I am trying to make a link pointing to # but am unable to find a method that works. The output i would like to see is <a href="#">Example</a> I have tried a few variations of the ...
Rob Holmes's user avatar
7 votes
5 answers
6k views

How to create a menu for current book

I want to create a menu that will be shown on the node if it is part of a book. For example like this: That menu should be shown for all books, which means I don't want to have a separate block for ...
Bulat's user avatar
  • 412
7 votes
1 answer
5k views

How do you clear menu caches programmatically?

I am developing a custom module. In this module, I want to delete menu caches programmatically. For this, I have used \Drupal::cache('menu')->invalidateAll(); // for clearing the menu cache \...
latikas's user avatar
  • 500
7 votes
1 answer
2k views

How to get a section of the menu tree based on the current node?

I am currently struggling to wrap my head around how the menu tree and menu link services work for outputting part of a menu with some custom requirements. Admittedly I don't have to do this very ...
Kevin's user avatar
  • 27.9k
7 votes
2 answers
2k views

managed links in Wysiwyg?

I am looking for a systematic way to deal with links in Drupal, like there is for images. For images, you add image field to content type, then install "Insert" module and you can use Wysiwyg to ...
camcam's user avatar
  • 2,111
6 votes
1 answer
22k views

Show all nested menu links in Drupal 7

How do I display all nested links in <ul><li> format in Drupal 7? The default code only displays the 1st level links even though they are arranged in the Drupal admin menu as nested: <?...
enchance's user avatar
  • 2,049
6 votes
4 answers
6k views

Migrating link fields to Drupal 8

I am trying to migrate a link field field_url from a Drupal 7 site to my Drupal 8 one. The link field is compound, it has a title and a url value. In my process plugin I am selecting the right values (...
itsututa's user avatar
  • 335
6 votes
3 answers
20k views

How do I add classes to main menu ul and li?

I want to generate the html elements and their classes to fit my styling of the main menu. I'm confused by all the near-possibilities offered in the api documentation and by looking at core themes etc....
iainH's user avatar
  • 1,374
6 votes
2 answers
11k views

how to make a field in a view be the link destination to another field?

I am trying to create ads on the sidebar to my site. I have created a content type that has 2 fields; an image field, and a link field. I now want to display the ads in a view by having the image ...
Ephraim's user avatar
  • 895
6 votes
3 answers
4k views

Render image that is linked

I am loading an unmananged image file and would like to render it in a block, but it should be linked. I have an uri (public://...) and I am able to render the image using $build['my_image'] = [ ...
tobias554's user avatar
6 votes
4 answers
14k views

Open a link in a new tab in the menu [closed]

I'm using Drupal 8 with Bootstrap theme, and I've created a sub-theme and different menus. I've tried to edit the menu twig template but i am not really familiar with Twig. How can I add a menu ...
usethe23's user avatar
  • 661
6 votes
3 answers
3k views

How can I add cache context to custom menu link?

I have two routes that receive user as route parameter, and i need a menu link for every one in account menu. So I added in my *links.menu.yml client_account_links: deriver: \Drupal\my_module\...
Roberto Araya's user avatar
6 votes
3 answers
16k views

Convert link from node/nid to Pathauto url?

Im using Pathauto to make my URLs nice and I may want to change the paths in the future. On some pages Im manually lining to other nodes. The issue is that if I code the nice URL then the link will ...
Evanss's user avatar
  • 2,026
6 votes
1 answer
4k views

How to show contextual links buttons in templates with minimal markup?

I want to get rid of the most markup in Drupal 8 templates, but still want to have working contextual links. How to do this?
Sachbearbeiter's user avatar
6 votes
2 answers
3k views

How can I add a span tag inside my menu link?

My twig file contains the following: <li{{ item.attributes.addClass(classes) }}> {{ link(item.title, item.url) }} </li> Which outputs: <li class="menu-item item--search"> &...
Kris Robinson's user avatar
6 votes
2 answers
4k views

Adding classes to menu items to signify what level they are

How can I add classes to the <a> or <li> tags of the main menu to signify which level they are in the menu hierarchy (e.g. "level-1", "level-2", etc.)? The code below shows the first link ...
enchance's user avatar
  • 2,049

1
2 3 4 5
33