Questions tagged [routes]

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

Filter by
Sorted by
Tagged with
102
votes
1answer
40k views

How should I implement hook_menu()?

What are the fundamentals of implementing hook_menu()? I would like to see the basics covered in a single question, to avoid having to answer the same similar but different questions over and over.
14
votes
3answers
11k views

How do I alter the route defined by another module?

In other words, what is the Drupl 8 equivalent of hook_menu_alter()? Drupal 8 still uses hook_menu(), but for what I can see, the information returned by the hook is different from what the hook ...
13
votes
7answers
17k views

How do I call the menu_rebuild function in Drupal 7?

I would like to call the menu_rebuild() function, but I am not sure of where exactly paste the code snippet. I can't find the update.php file anywhere in my local instance. The reason I would like ...
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'...
2
votes
2answers
2k views

How to force a redirect (override the destination query string in the URL)

I have a custom form submit callback to redirect users to a specific page: function MYMODULE_authfrontpageredirect_callback(array &$form, FormStateInterface &$form_state) { $url = \Drupal::...
7
votes
3answers
2k views

Slashes in single route parameter or other ways to handle a menu tail with dynamic number of params

According to the Symfony documentation, a route defined as below should trigger the specified controller for both /hello/bob and /hello/bob/bobby: _hello: path: /hello/{names} defaults: { ...
9
votes
2answers
10k views

What is the equivalent of hook_menu_alter() to change a menu item type?

I want to change the menu type in Drupal 8. In Drupal 7 we can achieve this using hook_menu_alter function module_menu_alter(&$items) { $items['admin/config/people/ip-blocking/default'] = array(...
7
votes
5answers
26k views

Customizing menu link output

In Drupal 7, how I can intercept menu rendering in template.php and add pipes after menu links? I tried using template_preprocess_menu_tree but I don't think that is what I am looking for. I want to ...
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 ...
27
votes
6answers
29k 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 ...
21
votes
2answers
22k views

What's the difference between access arguments and access callback?

What's the difference between access arguments and access callback? Suppose I set the access callback to 'user_access', and array('custom permission') is the value for the access arguments. What ...
14
votes
5answers
8k views

how to separate taxonomy hierarchy in pathauto with slashes

Pathauto seems to have a different way of aliasing taxonomy hierarchy. From Taxonomy Menu: Classifieds > Cars > Aston Martin > DB9 Coupe Classifieds > Jobs > Accounting What I want is something ...
12
votes
6answers
9k views

How to redirect an anonymous user to the login form after a 403 error?

I want to redirect an anonymous user to the login form if such user encounters a 403 error. I have created event subscriber and this is my code, but I end up on loop on the current page. /** * ...
11
votes
4answers
7k views

Increase memory limit doesn't help in Fatal error: Allowed memory size of …/modules/views/views.module on line 416

I've switched from Drupal 7.14 to 7.15 three weeks ago and therefore, I'm encountering a series of very sophisticated (for me) memory limit errors. Those errors occur any time I'm trying to clear ...
5
votes
2answers
367 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 ...
3
votes
3answers
11k views

Create alphabetical pager

I want to list all the posts with alphabetical headings like this site: How can I do this with drupal 7 using views?
7
votes
3answers
9k views

Menu links not being translated

I have installed Drupal 7 and also the internationalization modules. I am able to add a basic site and translate it. I can even opt to add localized url aliases which work fine when switching language....
4
votes
3answers
10k views

Taxonomy menu with custom path for taxonomy terms

I am trying to make a taxonomy menu using the Taxonomy Menu module with a custom path for the taxonomy terms. Instead of /taxonomy/term/tid I want /proj/!tid (or ultimately /proj/!term-name but I'll ...
4
votes
2answers
6k views

How to create views tabs in D8?

I can't get views tabs to work in D8, following the exact UI procedure that does work in D7. To be more precise, in D8 at /mypage I see no tabs at all, and at /mypage/tab2 and /mypage/tab3 I do see ...
0
votes
2answers
4k views

How to create a tabbed view in a panel without a menu entry?

What is my goal? I'd like to create a view for my users' profile page, similar to the 'Questions' block one finds on the user pages on this website. Instead of the user's questions, I'd like to ...
7
votes
1answer
16k views

How can I get $_POST data in a callback?

I've implemented hook_menu roughly as follows: function sample_menu() { return array( 'path/to/things' => array( 'page callback' => 'callback_function', '...
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"><...
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 ...
8
votes
1answer
3k views

Custom module with its own menu?

I am in the process of writing my 3rd custom module and this one is my biggest challenge yet. I know how to use hook_menu to generate menu items, and depending on the path you choose determines where ...
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\...
2
votes
2answers
620 views

How to show blocks by url, when nodes have multiple paths?

I know that having multiple path aliases to a single node is discouraged, but it is a situation I have to deal with. My node is accessible via /news/node-1, /baseball/news/node-1 and /basketball/news/...
0
votes
2answers
3k views

How to create custom menu link wrapper function in Drupal 7?

As you know default wrapper for menu item in Drupal 7 can be modified via function theme_menu_link(). by overriding theme_menu_link($variables) {} function we can modify the rendered html output ...
6
votes
2answers
21k 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: <?...
17
votes
2answers
28k views

Do you have an example of hook_menu() access callback?

I have downloaded the examples project, but in the menu_example module all the access callback are set to true.. hard to understand how it works. In my example, my meno entry should be visible on ...
15
votes
5answers
27k views

Create a menu programmatically in Drupal 7

A newbie question guys. Any thoughts how can I create a menu programmatically? Says I have 3 different menus I want to create. The first menu will be placed in the top left of the header. The second ...
12
votes
3answers
6k views

Redirect Anonymous user to login page

I want if user not logged in and visit any page of my website except my REST VIEWS routers I redirect him/her to login page in drupal 8, I found this solutions for drupal 7 but didn't find any ...
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 ...
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?
4
votes
2answers
9k views

HOOK_menu_alter to remove Main Menu items for specific user roles

I'm trying to add a menu link (admin/people/create?operator=1) to the Main Menu only for the user role of 'Supervisor.' I have tried to do this: function mymodule_menu_alter(&$items) { if(...
7
votes
2answers
2k views

How to add class in li element (for page where I am) in menu for drupal 8

I would like to add class in li element in menu for drupal 8 for page where I am. For example if i am on page Start, that li have active class. Or If I am on Join page that li element for join have ...
6
votes
3answers
4k views

hook_menu_alter() is not working

I have implemented hook_menu_alter() in a module I have created. I have printed something inside that function call but nothing shows up, though the function hook_init() is executed from the same ...
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
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 ...
3
votes
2answers
3k views

How do I implement the equivalent of hook_url_inbound_alter()?

I'm working on a module which will resolve URLs to entities by altering inbound URLs so that if they contain an entity ID with following pattern "-{entity_id}" user will be redirected to correct URL. ...
2
votes
3answers
19k views

Menu drop down in Drupal 7

I just started to learn and to develop a Drupal 7 site; therefore, I don't know Drupal very well. How can I create the menu used in these two sites, http://www.honda.com.my/ and http://www.toyota.com....
2
votes
1answer
473 views

Want parent MENU_LOCAL_TASK tab to show when on a child page

I have a set of local task menu items defined in my module. This includes the following items: control => MENU_NORMAL_ITEM control/jobs => MENU_DEFAULT_LOCAL_TASK control/jobs/% => MENU_??? control/...
2
votes
1answer
554 views

Change the URL of a node based on parent path

So let's say I have a basic page node. I want to have this as an entity reference inside another content type - let's say an event content type. So let's say that the event content has a url like ...
9
votes
2answers
4k views

Show menu items with limit access to anonymous users

I have a website that uses Private module in order set the access to the content, and of course some of my pages have menu items. Now if I set a page to be private, only users with proper permission ...
8
votes
2answers
2k views

Would redirecting users in hook_menu's access callback have any undesirable effects?

This answer led to a discussion about the best way to redirect a user to a specific page if they shouldn't have access to the page they are trying to access. One option is to set the access callback ...
6
votes
1answer
5k 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 ...
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
5answers
4k views

Any way to bulk delete menu items?

I just deleted 25 menu items and it took me some time to do it. Just wondering if is there any way (module) to bulk delete menu items.
5
votes
3answers
8k 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 ...
3
votes
2answers
1k views

Change '/user(/*)' URLs to 'profile(/*)'

I want change all /user, /user/* urls by /profile, /profile/* urls. From a custom module, I copied all user routes (found in /core/module/user/user.routing.yml) to my custom .routing.yml file. I ...
2
votes
2answers
376 views

Creating a responsive menu system for a site with a lot of content [closed]

I am currently creating a website which has a lot of content - text. For this I need a serious menu structure with 5-10 menu items per menu and at least 15 menu-blocks per main menu item. Further it ...