Questions tagged [navigation]

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

Filter by
Sorted by
Tagged with
39
votes
9answers
68k 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 ...
30
votes
9answers
64k 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 ...
0
votes
1answer
1k views

How to show authorized users a link for relevant Views results using the Rules Link module?

Assume a list of entities, created by the Views module. For example a list of "All blocked/active users" which looks like so: User name Active Created date Last login Hillary....
7
votes
2answers
8k 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 ...
27
votes
6answers
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 ...
14
votes
3answers
17k views

How do I create menu links programmatically?

I need to add some links to existing menu (or to new) programmatically in Drupal 8.
9
votes
2answers
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?
3
votes
3answers
4k views

Alter the access of menu links before rendering

I need to alter the access of menu links before being rendered. In Drupal 7, we used hook_translated_menu_link_alter() for it. Drupal 8 change records show that there are no direct replacement for ...
16
votes
10answers
19k 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 ...
8
votes
2answers
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 ...
6
votes
3answers
8k views

How do I programmatically update or delete menu items?

I have seen the post on how to create menu items programmatically in Drupal 8, but how do I update or delete menu items in D8? Clarification: by programmatically I mean dynamically so yaml config ...
3
votes
2answers
1k views

How can I add HTML tags into menu title?

How can I add HTML tags into menu title? I'm also tryed the following code. function adminimal_theme_preprocess_menu(&$vars) { if ($vars['menu_name'] === 'main') { $vars['items']['...
6
votes
2answers
2k 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\...
6
votes
2answers
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: <?...
22
votes
4answers
16k 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 ...
7
votes
5answers
8k 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?
11
votes
4answers
7k 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 ...
8
votes
2answers
8k 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 ...
4
votes
1answer
9k views

How to display a block with menu child items programmatically?

I need to create block with a list of links menu child items (only first level) of a given menu like this: Item 1 Item 2 Item 3 With this code I can have the menu items but I don't know how to ...
4
votes
3answers
1k views

Link format as a preview

I'm asking if it exists a drupal module that let you make a preview of a link like the Facebook do. In another way a display format which it gives a preview.
2
votes
2answers
4k views

Adding more variables to menu for use in menu.html.twig

I'm attempting to give menus more variables to work with besides the default menu_name,items, and attributes. This is because making a variable in the preprocess menu hook does not allow it to be ...
21
votes
7answers
13k 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 ...
9
votes
3answers
14k 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 ...
6
votes
1answer
6k views

Creating a Dropdown menu in Drupal 7

My question is how do we get the menu in drop down structure. i.e <ul><li><a></a><ul><li><a></a></li></ul></li></ul> I used ...
6
votes
3answers
15k 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 ...
3
votes
2answers
746 views

Dynamic local tasks - caching problems

I try to create some local second level tasks depending on some settings for a custom entity. But unfortunately sometimes these local tasks do not appear - they appear again when rebuilding caching ...
1
vote
1answer
3k views

How to update a menu link created with MenuLinkContent::create()?

I know how to search for menu items created with *.links.menu.yml: $menu_link_manager = \Drupal::service('plugin.manager.menu.link'); $menu_links = $menu_link_manager->loadLinksByRoute('user.page')...
8
votes
6answers
18k 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 ...
6
votes
2answers
2k 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 ...
4
votes
2answers
4k views

Drupal navigation always returns a 404 error

I have been given a Drupal site which I have to get it running. I have Apache / Drupal / MySQL up and running, and created a new .conf file in Active Sites, and set the document location to /var/www/...
4
votes
3answers
2k views

Get title from Route

I am trying to print out a few links on a custom page template. I would like to use the title and url from each route. I am trying to print out the title from the route. I know I can get the url ...
3
votes
2answers
364 views

How can I add a caption to my navigation menu?

How can I add a caption to a navigation menu in Drupal 6? I am trying to achieve this effect:
2
votes
1answer
618 views

Add field(s) to menu link?

Is there a way to add field(s) to menu links in Drupal 8? Like an image field to output above certain links?
2
votes
1answer
2k views

Add custom class to link outputted by views

I'm using views to output a link. The user gets two fields in which to add the href and the text on the link. I wan't them to be able to put a class on the link as well. How can I do this? In views I ...
1
vote
1answer
530 views

Adding a query string to menu items determined by the current node?

I'm pretty new to Drupal 8. I'm trying to figure out how to programmatically add a query string to a menu item link, the specific query string is determined by the node/page the user is currently on. ...
1
vote
1answer
202 views

Secondary & Tertiary links next to Parent links

How can I print expandable secondary and tertiary links to the right of the parent? For mobile, the secondary and tertiary links will need to stack below the parent links. Below is an example of what ...
0
votes
1answer
92 views

Menu in Drupal8

I am currently using below code to generate routes: foreach($this->hardcopyEntityManager->getHardcopyEntities() as $entity_type => $entity_definition) { $route = new Route( "...
11
votes
6answers
13k 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. ...
13
votes
2answers
11k 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?
8
votes
1answer
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 ...
5
votes
3answers
9k views

Add a class to main menu links

I've searched and found variations of this question but I've never found an answer that seemed to work. I need to add a class to the <li> elements, currently the main menu is rendered like this: ...
6
votes
5answers
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 ...
6
votes
2answers
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 ...
5
votes
1answer
20k views

How to add additional url parameters?

I would like to know how I can include additional URL parameters to a given link? ie: 'news?pid=3' <?php print $path='news?pid=3'; ?> This returns page not found error as the '?' is getting ...
4
votes
4answers
5k views

User picture and name in user menu

I would like to achieve what Acquia did on https://dev.twitter.com/. When you sign in, you can see the user picture and the user name in the right end of the menu bar and that is what I need. I made ...
11
votes
4answers
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 ...
11
votes
6answers
4k 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 ...
5
votes
3answers
7k views

target=_blank for links in view

I've got a view and one of the fields is displayed as a link. (Output this field as a link is cheked). But now i want those links to have target=_blank attribute. How can i achieve this?
5
votes
2answers
7k views

How do I get the absolute URL when using l()?

I want to get <a href="http://site.ru/node/123">New product</a> from l(), and I call it as l('New product', 'node/123'), but this function generates a URL that is not absolute. How can I ...
3
votes
1answer
7k views

Get menu link item from MenuLinkTreeElement

Hey I am loading a drupal 8 menu in the following way: if ($menu != NULL) { $tree = \Drupal::menuTree() ->load("my_menu", new MenuTreeParameters()); This returns MenuLinkTreeElement ...