Questions tagged [routes]

Using a term introduced in Drupal 8, routes are the paths to which modules respond.

Filter by
Sorted by
Tagged with
5
votes
2answers
14k views

How do I add classes to main menu ul and li in Drupal 8

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 ...
5
votes
3answers
5k views

How to abort the ajax request and redirect in the ajax callback of form element

I want to redirect the page in the ajax callback function, and nothing (like "header", "drupal_goto" etc.) works for redirect in the ajax callback function.
5
votes
2answers
6k views

Overriding menu.html.twig just for the primary menu

Drupal 8 Beta 1 has a lot of nice templates to use which can be brought into a custom theme and then customized. I brought in core's menu.html.twig into my custom theme and indeed I can customize ...
5
votes
2answers
376 views

Do new routes in Drupal 8 *require* a static first portion?

Using mymodule.routing.yml, I can successfully create a custom route at /foo/{bar}/{baz}. I cannot seem to do either of /{bar}/{baz} or /{bar}/foo/{baz}. It just returns 404. Why? Is there any way ...
5
votes
3answers
3k views

How do I correctly setup caching for my custom API routing?

I have custom module with some routes which return JSON, for instance terms of a vocabulary. routing.yml mymodule.terms: path: '/api/terms/{vid}' defaults: _controller: '\Drupal\mymodule\...
5
votes
4answers
1k views

How do I increase the number of shortcuts allowed in admin menu?

The number of shorctuts is limited to 7 (second row) When I add an 8th shortcut it is in the disabled section How do I change that?
5
votes
2answers
9k views

How and where do I programmatically add a menu to the Navigation menu?

I want to add menu items to the Navigation menu dynamically, depending on certain states (example: user is logged in, etc). I assume I do this in theme_preprocess, but I can't seem to find the var to ...
5
votes
2answers
1k 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
1answer
2k views

Debug “Access Denied”

Is there a way for debugging "Access Denied" errors in Drupal 8? I'm having some routing/permission issues, and I would like to be able to debug why i'm getting "Access Denied".
5
votes
1answer
2k views

How to move the edit tab in node.tpl.php

The $tabs variable is being printed in page.tpl.php, but I want to move it under the title of my node. I can't use the $tabs variable in my node template and I don't see the variable being prepared in ...
5
votes
3answers
9k views

Showing a node edit page with drupal_get_form() and hook_menu()

I am using drupal 7 and am stuck at a very basic problem. I would like to simply show the edit page to a known node id. I know there are similar posts but they either didn't work or I didn't ...
5
votes
1answer
3k views

Why do sub-menu items not appear on front page, but work on other pages?

I have added a link to a Panels page in my main menu. Beneath that link are items which link to a couple of Webform pages and a Basic page. On the home page, the sub-items do not appear beneath the ...
5
votes
5answers
14k views

How do I modify /user to a custom URL?

I have some small Drupal 7 sites that don't require me to log in all the times, and there are no users. I would like to change the user login path to something else to deter bots targeting Drupal ...
5
votes
3answers
3k views

How do I create extra permissions for an eck created entity?

I have created an entity using Entity Construction Kit (ECK) and wish to add extra permissions for that entity such as view own, edit own and delete own. I see there has been some movement in this ...
5
votes
3answers
2k views

Using menu tab for each panel variant

I'm trying to use Panels to arrange content on my site. I've made some strides in creating a panel that displays a view of images based on different criteria. I added a page (panel) which allows me ...
5
votes
3answers
8k views

How to set the parent of menu items creating using hook_menu()?

I need creating a series of menu items dynamically based on values from the database. Here is a example of my hook_menu() function; in this snippet, I removed the DB queries and just added an array ...
5
votes
3answers
8k views

How to hide/remove a specific menu heading tittle

I have created a menu using Superfish containing the following items: "Menu 1," "Menu 2," "Menu 3," and "Contact." When I click on each menu, the heading title is displayed. I want to hide the ...
5
votes
2answers
4k views

Why does the page callback have two arguments?

function menufun_menu() { $items['menufun/%/bar/baz'] = array( 'title' => 'Hi', 'page callback' => 'menufun_hello', 'page arguments' => array(1), // The matched wildcard. '...
5
votes
3answers
2k views

What are some drupal 7 mega menus that allows view blocks to be inserted?

I was wondering what mega menu's for drupal 7 that allow view blocks to be inserted? Currently I only know about xo mega menu, but i was wondering what other ones do people use or other workarounds ...
5
votes
1answer
549 views

How do I add a menu router that works even in the maintenance mode?

when a Drupal site is in maintenance mode (not due to a technical fault), users without permission cannot access any page other than /user. Is there any special hook to define a specific menu router ...
5
votes
1answer
3k views

Drupal 8 - “Implement menu links as plugins”, trying to build a menu tree

In a previous Drupal 8 menu question here, we determined that menu tree building was now a service. In my D8 contrib theme, I was then able to render the main menu tree as: function ...
5
votes
1answer
469 views

What does the menu_masks variable do?

When I was building a feature (as in Features), I noticed the menu_masks variable. I have read menu_get_ancestors() and _menu_router_save() but I still don't understand what it does. On a more ...
5
votes
3answers
17k views

How can I show/hide just one menu item based on user role?

I have a single menu item that I would like to show or hide based on user role. Use case: I have a membership site with paid and free memberships. In the navigation menu, I want to show a link for ...
5
votes
3answers
10k views

Change menu link title dynamically?

I'm trying to alter the text of a menu item dynamically based upon certain variables. I'm using hook_menu_alter like this: function mymodule_menu_alter(&$items) { $items['toggle-review-process'...
5
votes
2answers
3k views

Show a menu block only on nodes that belongs to this menu

I am trying to accomplish something similar to the book navigation module. Say I create a block containing a menu. I want this block to become visible for nodes that belong to this menu. So if NodeA ...
5
votes
1answer
93 views

Why is this extremely simple form not getting an upcast entity from its route?

I have a my_job_board.routing.yml: my_job_board.user_register_form: path: '/my-job-board/register/{user_role}' defaults: _form: '\Drupal\my_job_board\Form\UserRegisterForm' _title: '...
5
votes
2answers
803 views

How can I make my main menu link text dynamic?

How can I make my main menu link text dynamic? My solution: I tried to use Felix's answer, below, but it would not work for me. Obviously, the method suggested by Felix has worked for others and it ...
5
votes
1answer
540 views

Is it possible to remove Route objects from a RouteCollection object?

When I look at the code used for the method handling a RoutingEvents::DYNAMIC event, which receives a RouteBuildEvent object, I notice the code is always similar to the following one. $collection = $...
5
votes
5answers
12k views

How to include a custom menu in page.tpl

I want to code a custom menu straight into page.tpl.php. The default theme uses <?php if ($main_menu): ?> <div id="main-menu" class="navigation"> <?php print theme('...
5
votes
6answers
4k views

How to add html tags in drupal 7 menu?

I would like to add <br> tag or &nbsp; character to html menu, but when I type Home <br> Page, it does display as plain text, but I want to break that words by two lines. How can I ...
5
votes
1answer
2k views

Overriding page.tpl.php for a menu_hook page

I am trying to override template for a custom page I have in hook_menu. $items['announce_your_new_products'] = array( 'title' => 'Announce Your New Products', 'description' => '...
5
votes
1answer
5k views

How do I theme a menu to have a wrapper div with menu name?

The default menu theme function doesn't output the menu name (see below). function theme_menu_tree($variables) { return '<ul class="menu">' . $variables['tree'] . '</ul>'; } I've ...
5
votes
2answers
5k views

D7 - How to get mlid value from path of menu item

Quick question. How to get mlid value from path of menu item. There is a function called menu_link_load() but it requires an mlid value, but I need something exacly the same function using path.
5
votes
1answer
301 views

Module to list menu_router / path debug info? [closed]

Every now and then, mostly when looking at a new site, I find myself wanting to know What's the source of this particular page? Usually, I end up starting to dig in the menu_router table, and ...
5
votes
4answers
1k views

Previous/ next navigation in taxonomy terms

Due to some complex project, I would like to organize navigation between taxonomy terms programmatically, with generation of custom links. Example of navigation I need in vocabulary "fruits" with ...
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: ...
5
votes
3answers
1k views

Add custom class to a particular menu

I need to know how to add extra class to a perticular menu.For example i have custom menu "menu-header-let",This menu is rendering like below, <ul class="menu"><li class="leaf first"><...
5
votes
2answers
6k views

How do I theme (add extra markup to) menu links in Drupal 7?

I have a secondary menu that displays like: <ul class="secondarynav"> <li class="menu-428 first"> <a href="/content/page">PAGE</a> </li> ... I would like to change that ...
5
votes
1answer
1k views

How do I define a Route with multiple different paths?

Does Drupal's routing system support a regular expression or other means for multiple route paths? I have a route that I would like to be able to hit from two different endpoints, /api/v1/foo and /api/...
5
votes
1answer
94 views

hook_menu_alter with Organic Groups

I want to change the menu button on my main nav bar depending if the user is or isn't a member of a group. I need one button to 'register' if the user isn't part of a group and that same button ...
5
votes
5answers
3k views

Show a link in a menu even if user has no access

I created a node/add/content-type menu link in my main menu, but it only shows to those who have access to it. How could I show this to everyone, including anonymous users, and use http://drupal.org/...
5
votes
3answers
1k views

Displaying node reference select list as ordered menu list

I want to display the Node Reference Select List (usually a long list of nodes, unordered and generally quite long) as an ordered bunch of nodes, that replicate the structure of the menu system. The ...
5
votes
2answers
422 views

Ajax %-wildcard URL giving 404 error when setting a parameter

I have a page with a dropdown. When you click on that dropdown that content is loaded by Ajax. I would like to do the same for the Breadcrumb, so I created an Ajax-URL in my module: function ...
5
votes
1answer
2k views

How to apply theme_menu_tree to only the top <ul> menu

I am using the following function in the template.php (drupal 7) to override the original menu output. However, the tags in all levels are also affected. I wonder how to only apply it to the top/...
5
votes
2answers
1k views

Attach a node to a menu link OR attach custom fields to menu links?

My client would like to add content to the top-level links in the main menu, in order to have "Featured" content that is displayed in the drop-down menu. They must be able to choose which piece of ...
5
votes
1answer
208 views

Adding tabbed content in D7

What module should I use to make a tabbed block bringing views, custom content or forms? For example I want to have a News | Twitter | Facebook | Feedback Which would have a list of news (or a ...
5
votes
1answer
1k views

Route parameter upcasting and route access?

Original problem: I am trying to do a couple of (seemingly) simple things to convert a module I made in Drupal 7 to Drupal 8 (RC1). First I will note I am using the File Entity module in Drupal 8, ...
5
votes
1answer
3k views

Main Menu vs Navigation Menu

Is there a commonly accepted "best practice" for how to use the "Main Menu" vs the "Navigation Menu"? The descriptions in Core add to my confusion: "The Main menu is used on many sites to show the ...
4
votes
6answers
11k views

How do I insert a <span> </span> tag inside the <a> </a> tag on my main menu

I have asked exactly this question on Stack Overflow, but it makes more sense to ask it here. I'm trying to make the text between my tag not display by wrapping it in a and then styling that. I've ...
4
votes
3answers
5k views

How can I add a direct link to the edit account settings page in a menu?

Ok, I must be missing something obvious, but I'm having trouble adding a link to user/%/edit to the main menu. In the Menu UI, I clicked "add link," set the title to "Account settings," and then was ...