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.
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 ...
24
votes
1answer
29k views

Get the route name of the current page

The route name of the current page is available in page.html.twig? The page is generated by the default feedback form.
24
votes
1answer
3k views

Why are routing files filled with underscores?

What is the deal with all the parameters with, and without, a prefixed underscore character? Where does Drupal decide how to process these parameters? Was this concept introduced from Symfony, or is ...
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 ...
20
votes
10answers
22k views

How do I add a hash link in menus?

Is there a way to add a hashed link in the menu under drupal menu to just make a menu item that jumps down to an anchor or id on the page?
19
votes
1answer
2k views

In views, what is the difference between Normal menu entry, Menu tab and Default menu tab

When adding a menu item in views I see three selections that are ambiguius Normal menu entry Menu tab Default menu tab What is the difference and when would I use each?
18
votes
4answers
8k views

Access denied occurs after translate menu link

I want to translate my menu, I have installed internationalization, variable and locale modules but on my menu items when I click on translate : An access Denied page is displayed : What am I doing ...
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 ...
17
votes
9answers
24k views

How can I create a view of child nodes based on the menu relationship?

Say you have the following pages in a menu tree: Projects Project One Project Two Project Three I'm looking for a way to create a view that will be embedded in the Project (parent) page that will ...
17
votes
5answers
6k views

How do I add an access condition to a menu item?

How can I add new conditions on top of existing conditions that determine whether a menu item is visible? These conditions should not be limited to permissions settings. As an example use case (not ...
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 ...
15
votes
1answer
9k views

How to use “user logged in” as an access argument for a MENU_CALLBACK?

I would like to require that users be logged in to access a particular MENU_CALLBACK. The following works, but only for the admin account. Regular users are still denied access: 'access arguments' =...
15
votes
4answers
23k views

Advanced menu theming in Drupal 7

I've cruised around the web and it is not at all obvious how to theme custom menus. I've looked for hours and have not found one single post that illustrates the process, from start to finish, of ...
14
votes
1answer
18k views

create tabs with hook_menu() for custom module

since two hours im trying to create tabs in my custom modules backend. I've tried severals suggestions but couldn't get any of them to work. this is my current hook_menu() : function ...
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 ...
14
votes
2answers
10k views

How can I get the nid of a node from the page alias?

I want to be able to get the nid but the only information I have is http://example.com/this-is-the-alias. Is there a drupal function to get either the internal path of /node/* for that alias if I am ...
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 ...
14
votes
2answers
2k views

If two modules both defined the same menu path in 'hook_menu', which one Drupal will choose?

For example, "moduleone" defines the path 'admin/hello', which output print_moduleone_stuff(). /** * Implements hook_menu() */ function moduleone_menu() { $items['admin/hello'] = array( '...
14
votes
6answers
13k views

How do I use URL aliases in menus?

I am kicking the tires on Drupal 7 by spinning up a test site. I chose the Danland theme and created various pages with URL Aliases for each, but when I create the Menu link for each, I can only ...
13
votes
5answers
11k views

How to get route name of a view page?

In my custom submit handler I want to redirect to a view page Url, let's suppose my view name is team and its path is /admin/team, I find out I should use $from_state->setRedirect('route'); but ...
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 ...
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. /** * ...
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 ...
12
votes
5answers
8k views

How can I inject a taxonomy menu as the sub-menu of a standard menu item?

I have a main menu, with a top-level structure similar to the following: Home - Categories - Something Else - ... - Contact Each of those top-level links goes to an appropriate node page. I have a ...
12
votes
1answer
11k views

Can I add a custom link to “Main Menu” via hook_menu?

I'm trying to add a new link to the Main Menu from inside my module. Currently, this code: function custom_food_orders_menu() { $items['order_food'] = array( 'title' => 'Order Food', '...
12
votes
2answers
562 views

Problem trying to create a views with tabs. Link of tab doesn't point to the path I set

I am trying to create a views with tabs: so that a page that has several tabs, the View has a primary page that shows all Article nodes, a tab for all Event nodes, and a tab for Blog nodes. Something ...
11
votes
5answers
2k views

Should I use t() in a hook_menu's description?

I have always used t() for hook_menus title and description like this: $items['some-path'] = array( 'title' => t('My Page Title'), 'description' => t('This is a description about what ...
11
votes
2answers
29k views

How to theme a menu block?

I have created a custom menu (lets call it "mynav") and in my theme I've created a template specifically for it (block--menu--menu-mynav.tpl.php) which contains: <div id="mynav" class="<?php ...
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 ...
11
votes
4answers
3k views

How do I add custom tab in the user profile page?

I need to add a custom tab in user profile page. I defined my route like below: mymodule.routing.yml mymodule.account: path: '/user/{user}/custom' defaults: _form: '\Drupal\mymodule\Form\...
11
votes
2answers
286 views

What is the reason behind the current menu structuring

I'm not much of a Drupal Ninja; from what I saw at http://drupal.org/node/788972, Drupal seems to have a menu structure like Joomla, in the sense that it allows menu items to be created under menu ...
10
votes
3answers
7k views

If you update a routes file in Drupal 8 how do you clear the cache?

Having worked with Drupal 7 since its launch, I'm learning Drupal 8. At the moment I'm finding that whenever I change anything I have to do drush cache-rebuild to get things working again. On my VPS ...
10
votes
3answers
3k views

Custom menu as admin menu

Is there a module that take a custom menu and show it like Admin menu? I want to create my custom menu and then display it like admin menu (only for some roles). I've tried some modules but: Admin ...
10
votes
6answers
11k views

How to output child links based on the current page

When landing on a page which has a menu item that is a parent to other pages menu items, I would like to be able to show a list of those child menu items. I am using the following code. $trail = ...
10
votes
5answers
7k views

How do I create relative menu links?

I am busy working on a site on my localhost that needs to link to some content that is separate from Drupal. I have the current menu paths set up like this: http://mylocalsite/...
10
votes
4answers
3k views

Content Access module hiding menu links

I am using Content Access module with Drupal 7. when i restrict node access from a specific role, it also hide link in menu. is there any way to show restricted links in main menu?
9
votes
2answers
11k 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(...
9
votes
2answers
8k views

How to test if current page is an admin page?

At some point I started using the following code to test if current page is an admin page: $route = \Drupal::routeMatch()->getRouteObject(); $is_admin = \Drupal::service('router.admin_context'...
9
votes
1answer
4k views

Add tab / local task to a node

I've created a module called hotel_reviews. I've created the route node/{node}/reviews using hotel_reviews.routing.yml. hotel_reviews.content: path: '/node/{node}/reviews' defaults: ...
9
votes
3answers
13k views

How to completely wipe and rebuild drupal menus?

A while ago I found a cool blog post that detailed how to empty the menu tables, and rebuild the menu system with a drush php call, a necessity since the site will be unusable after emptying those ...
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 ...
9
votes
2answers
12k views

How do I display submenus separately from their menu tree? [closed]

I'm trying to display all 3rd level submenus for a menu item on one page, with each in its own display block. I've tried the Menu Block module but it only seems to work for the active trail, which ...
9
votes
1answer
193 views

Altering all urls to include extra information

What hooks are available for altering the urls? For example, there are language modules that, when enabled, provide urls such as /en/node/1 rather than leaving it as /node/1. I want to have something ...
9
votes
2answers
3k views

How to add a local task tab to node view? [closed]

I'm trying to add an extra tab to the node 'view' and 'edit' tabs. My module is enabled fine and I have cleared cache, but my new tab doesn't appear. What am I missing? /** * Implements hook_menu()....
8
votes
3answers
6k views

Why does not hook_menu_link_alter() work?

i want to expand my theme's primary links, so I put the following code in my custom module. function mymodulename_menu_link_alter(&$item, $menu) { if ($item['menu_name'] == 'primary-links') { ...
8
votes
2answers
3k views

How do I verify a route exists?

In Drupal 8, I need to verify a route exists or not in a custom module. How can I achieve this?
8
votes
2answers
2k views

How to set admin theme for a route?

According to Drupal handbook route definition accepts parameter called _theme. Unfortunately this parameter is documented as "TODO". Can this be used to force admin theme for the route? Is it ...
8
votes
1answer
3k views

How to turn off “<em class=”placeholder“> </em>” surrounding vars in the output of t()?

In my module I display a menu inside a block using drupal_render(menu_tree('my-menu')). In the output the variables printed with t() are surrounded by <em class="placeholder"> </em>. ...
8
votes
1answer
327 views

How do I implement routes?

How can I implement the most basic route in Drupal 8? What files do I have to write, and which classes do I need to implement?