Questions tagged [navigation]
Use it for questions about navigation menus and links used in a site.
133
questions
59
votes
14
answers
121k
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 ...
36
votes
10
answers
92k
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
1
answer
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....
8
votes
2
answers
11k
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 ...
3
votes
2
answers
1k
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 ...
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 ...
13
votes
4
answers
26k
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
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?
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\...
5
votes
3
answers
6k
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 ...
5
votes
1
answer
13k
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 ...
23
votes
4
answers
19k
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 ...
17
votes
10
answers
27k
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 ...
7
votes
5
answers
12k
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.
5
votes
1
answer
11k
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 ...
3
votes
2
answers
2k
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']['...
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 ...
15
votes
5
answers
28k
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; ...
13
votes
5
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 ...
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 ...
10
votes
3
answers
20k
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 ...
10
votes
6
answers
22k
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 ...
9
votes
2
answers
11k
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 ...
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 ...
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?
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 ...
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....
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:
<?...
6
votes
1
answer
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
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 ...
4
votes
2
answers
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
4
answers
3k
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
2
answers
3k
views
Determine which region a menu block is rendered in
I need to re-use the same menu in two different regions, with slightly different markup. My thought was to simply check which region the block was being rendered in, and use if statements to modify ...
3
votes
2
answers
367
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:
3
votes
1
answer
741
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.
...
2
votes
2
answers
1k
views
Don't link menu in the active page
My Q is equal as Remove link from active page in menu
I need the active page in my menu not to be a link.
So let's say I'm on the services page, I need my menu structure to
look like this:
&...
2
votes
1
answer
1k
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
1
answer
5k
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')...
2
votes
1
answer
3k
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 ...
2
votes
3
answers
6k
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 ...
1
vote
2
answers
290
views
How to increase book weight range for a same-level chapters
I have a book of 33 chapters. These chapters are numbered with roman numbers: Chapter I, chapter II and so on.I'm a blind user, so I can't use drag & drop reorder. In Drupal 7, weight range is -15 ...
1
vote
1
answer
240
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
1
answer
94
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(
"...
16
votes
3
answers
16k
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?
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 ...
11
votes
7
answers
17k
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. ...
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 ...
8
votes
1
answer
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 ...
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 ...
6
votes
4
answers
5k
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 (...