Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Questions tagged [routes]

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

Filter by
Sorted by
Tagged with
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 ...
8
votes
2answers
168 views

How to call a function when a node is being viewed?

Whenever I view a node page, I want to call a function but I'm not sure how to do that. I was thinking I should use hook_menu() and declare the path as node/%, and attach a callback function to that ...
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 ...
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 ...
8
votes
2answers
3k views

What is the equivalent of hook_translated_menu_link_alter() to Alter a menu link?

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; if (!...
7
votes
5answers
27k 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 ...
7
votes
2answers
4k views

How to show a menu item for anonymous users only?

I want to show a "Join Now" tab on the main menu for anonymous users only. In the past I used Menu per Role module which does exactly that. Since it's only one tab I would rather use 5 or 10 lines ...
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?
7
votes
1answer
17k 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', '...
7
votes
2answers
17k views

Pass arguments using hook_menu

I would build a confirmation screen. So I initialized the path in the hook_menu as it should be but for some reason, the argument $node isn't send with the function... What am I doing wrong? This is ...
7
votes
2answers
3k 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 ...
7
votes
1answer
2k views

How do I make the custom module “Configure” option appear on the module list?

I have written a simple module that implements hook_menu() (the added path is admin/settings/mymodule"). On the admin/modules page which lists all the present modules, there is no "Configure" link ...
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....
7
votes
1answer
2k views

how to add “access callback” function to a path defined by a view?

I'm using Drupal 7, Views 3, and hook_menu_alter function MYMODULE_menu_alter(&$items){ $items['client/place/%'] = array( 'access callback' => 'custom_function', ); } to override ...
7
votes
2answers
3k views

What is the equivalent of theme_menu_item in Drupal 7?

I know that in drupal 6 exist: theme_menu_item, but in drupal 7 there is not. Is there any replacements so that I modify the output for main system menu ? Actually I want to do a kind of filter of ...
7
votes
5answers
14k views

How to correct disappearing admin menu?

I use the Admin Menu module for my projects. In my Drupal 7 and Pressflow 7 instances, it randomly shows only some menu items. At first, I thought I could correct this by clearing menu cache. When I ...
7
votes
3answers
12k views

How to show/hide a link based on a permission?

I'm looking for a way to hide/show a link from the main-menu if the current user has a specific permission. The menu item has already been created and the menu item links to a node that is controlled ...
7
votes
2answers
10k views

Theming a custom menu block in Drupal 7

So I created a custom menu through the Drupal administration and named it "More Menu." Its machine name, menu-more-menu, was auto-generated by Drupal. Creating this menu automatically created its ...
7
votes
3answers
1k views

Changing the tite of your page to match the title of your tabs

I have the following function: function cvminterviews_menu() { $items = array(); $items['admin/settings/cvminterviews'] = array( 'title' => 'Interview Schedule Overview', '...
7
votes
3answers
1k views

How to use URL parameter and page callbacks for tab menus correctly?

I'm using Drupal 6 and I'm trying to display two tab (menus) on a page that has the URL /vehicle_info. Both pages that the tabs link to should take a node's nid as parameter. My current code looks as ...
6
votes
5answers
20k views

How to set a menu item active ?

I have a site that has a lot of menus. One of them is the main menu that has few items. These items link to main areas of the site, and each of these main areas has one specific menu. When I'm on a ...
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: <?...
6
votes
2answers
6k views

Is there some way to arbitrarily set the active trail?

I have a menu as such: Home Performances News Learning ... I have a content type called 'Event' and when viewing a node of the event type I want to set the 'Performances' menu item as active. How ...
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 ...
6
votes
1answer
5k views

How to Trigger Existing, Non-Form Ajax from JavaScript Event

I'm trying to figure out AJAX in Drupal 8. I have a custom module that works, using AJAX to change the content of a div when a link is clicked. The API says: Many different events can trigger ...
6
votes
1answer
990 views

What is the convention for naming routes?

Lets say I have these paths: /admin /admin/settings /admin/settings/myentities myentity/id /admin/settings/myentities/id/edit /admin/settings/myentities/id/delete What would be the proper route ...
6
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 ...
6
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".
6
votes
3answers
6k views

Add class to top-level ul using menu_block

I am using the Menu Block Module to generate my main and sub navs. I want to add a class to the ul for just the top level of the main nav. As I understand it, I can do something like this: function ...
6
votes
2answers
3k views

Overriding hook_menu() { $items }

For example, here's a snippet form the Comments Module (comment.module): function comment_menu() { $items['comment/%'] = array( 'title' => 'Comment permalink', 'page callback' => '...
6
votes
3answers
5k views

Dropdown Menu Dummy Link

One of my menu items I have, I want to make it so that only the child links are clickable, and the parent is not. Is there a way to make the parent a sort of "Dummy Link" just to set a hierarchy for a ...
6
votes
3answers
1k views

Disable the /blog route

I'm using Drupal 6.16. I would like to permanently disable the /blog path (and all its sub-paths, but not the Blog module. Is this possible?
6
votes
1answer
214 views

How can I override a module's file via hook_menu_alter()?

I have the following code in my hook_menu_alter(). <?php function bonus_menu_alter(&$items) { if (!empty($items['things'])){ $items['things']['title'] = t("New title"); $items['...
6
votes
1answer
5k views

Update a menu link programmatically

For a migration project, we had some links on the main menu stubbed out to an external site. Now I want to update the links with their actual final path. However, I can't do this beforehand, because I ...
6
votes
1answer
474 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 ...
6
votes
4answers
5k views

How NOT to cache a hook_menu callback

I wrote a callback in my hook_menu() implementation, wich won't work the way it is intended to because of caching. The callback just returns some text depending on a cookie. Something like that: ...
6
votes
1answer
166 views

Which menu should a third-party module choose, between “Structure” and “Configuration”?

I noticed that some module prefers to add their menu items under "Structure," while other modules prefer to add them under "Configuration." I thought that the reason of choosing "Structure" was ...
6
votes
2answers
5k views

Can you make the hook_menu() item title different from the page title?

I'm building a menu with hook_menu(). When you're building the array for this you specify a title, which is then passed to the page you call and becomes the page title. It's also the menu item's ...
6
votes
2answers
4k views

Export menu as feature?

How can I export a menu as a feature? I found the menu import module, but it does not work with this feature.
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 ...
6
votes
2answers
237 views

What does a value like node:{node_type} mean?

I'm trying to fully understand Drupal 8 routing. I understand the basics, no problem, but some of the finer details are still a mystery. Here's the route for adding a node from the node module. node....
6
votes
1answer
3k views

Theming main menu with block--menu.tpl.php not working

My template file block--menu.tpl.php is not catching my main menu block. It works for custom menus. Am I missing something on this? I don't have any other specific block overrides. I'm running Drupal ...
6
votes
2answers
3k views

What trigger menu_rebuild flag in semaphore table? [closed]

Well, this question appear to be simple, but my problem is a little bit more complex. I'll try to explain my situation. I have a site with customized template and a bunch of modules (all 3rd party ...
6
votes
1answer
597 views

How do I provide multiple menu tabs for a view?

I have a view to select many articles with a specific taxonomy term with a path of Example.com/materials/% where the % uses a contextual filter to pick the correct material. The filter works. ...
6
votes
6answers
3k views

Managing large volume of content in tree hierarchy

Firstly I apologise if this has already been answered. I thought it would be a common problem and I'm surprised that I haven't found a general solution anywhere. I have a large corporate website (...
6
votes
3answers
562 views

Converting hard-coded menus to using the Menu module

I have a site built in Drupal 7 with the navigation hard-coded in template.tpl.php. How do I go about switching this over to use the menu module instead? I've already have the menu recreated in the ...
6
votes
1answer
398 views

Dynamic menu linking to the forum associated with the current Organic Group

I've got two groups. I've got two forums belonging to each group. I've got a panel set up to display a custom view of forum topics that are defaulted to the group id, so that when given the group id ...
6
votes
2answers
3k views

How to set required POST parameters for routes

With GET method we can do something like this example.user path: 'example/{user}' defaults: _controller: '\Drupal\example\Controller\ExampleController::content' requirements: ...
5
votes
7answers
13k views

How to add / remove tabs from user profile?

By clicking on the "My account" link that on the secondary menu on the site, the user is redirecting to the user's profile page. In this page there are many tabs. Some tabs are there originally, and ...
5
votes
3answers
5k views

Dynamic menu items

The Drupal 8 menu system is much more logical than in previous versions, and breaking the many functions of hook_menu() into multiple YAML files makes perfect sense and simplifies the creation and ...