Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [routes]

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

3
votes
1answer
1k views

Custom validation of route parameters

I have something like the following on my .routing.yml file: my.path: path: '/my-path/{node}' defaults: _form: 'Drupal\mymodule\Form\MyForm' requirements: _entity_access: 'node.update' ...
1
vote
3answers
61 views

Adding new menu items to hook_menu

I am building a module which already has the function Mymodule_menu() at the beginning of the code. I was wondering if it is possible to use hook_menu_alter() to add new menu items (i.e. building new ...
1
vote
1answer
1k views

Alter entity.user.canonical (/user/{uid}) route

When a user (e.g. nid = 37) goes to some other user's profile page at a url like /user/1, /user/2, ..., /user/n, I want automatically redirect them to their own: /user/37 page. How can I do properly ...
4
votes
1answer
1k views

Wildcard for routes

How can I pass the complete path arguments to a route defined in a mymodule.routing.yml file? example_archive.content_archiv: path: '/examplearchiv/{myvalue}' defaults: _controller: '\Drupal\...
0
votes
3answers
900 views

Entity form additional arguments

I have normal Drupal8 Content entity, and I'd like to set up some additional arguments for the entity form builder. Ie I have entity form path like so: /tilaus/uusi/{tilaus_type} and I'd like to add ...
7
votes
2answers
6k 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'...
4
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 ...
1
vote
2answers
397 views

Handling external authentication with routing.yml

I am building a new page (general use of "page", not literally referring to the node type) in my Drupal site that should only be accessible to members that have a certain permission. I have defined ...
1
vote
2answers
2k views

Create route that returns XML Feed [closed]

How do I create a page that returns an XML feed?
3
votes
1answer
3k views

How to get the Route object from an URI?

If I have a Url object, or even a simple string representation of path such as /node/2, how can I get the full Route object?
3
votes
2answers
2k views

How to get language specific path in twig?

In a twig template you are able to get a relative path by using {{ path('entity.node.edit_form', {'node': nid }) }}. The path will be in current language. Now I need to get the path in a specfic ...
1
vote
1answer
1k views

Translate routing and menu titles

I've made two yml files, for both routing and menu item: Route: tester_helper.products_controller_overview: path: '/assortment' defaults: _controller: '\Drupal\tester_helper\Controller\...
1
vote
1answer
292 views

Getting $_POST empty in AJAX callback

I just want to send address information to drupal for check content existence through the AJAX. Request is sending successfully and callback function also executing. but I am not getting any data in $...
1
vote
1answer
62 views

hook_menu() to display node view mode

How to create hook_menu to display node view mode? node/% - full view mode (default) node/%/subpage - custom created view mode of this node, for example "subpage" I've tried this: How to render ...
3
votes
1answer
906 views

Redirect using a path [duplicate]

My question seems to be obvious but I really don't find the solution. Well, I want to redirect to my view just after connexion. I try to use $form_state->setRedirect,but It's seems it needs the route ...
3
votes
1answer
525 views

Take over display of a content type node route

I have a discussion content type. I would like the primary viewing experience (at "discussion/discussion-name") to be a cacheable form using a form mode. Basically, I'm trying to create something ...
3
votes
1answer
1k views

How do I create menu programmatically?

I read through the Drupal 8 menu_api documentation in drupal.org. The example guide lists an option to create menu links and insert them into an existing menu. How does one create menu itself first ...
-1
votes
1answer
597 views

Clear cache routing.

I follow topic to create dynamic routes. Examples i have a form, when user click submit form. new route will be created. It's working. But after clear cache by UI (or function drupal_flush_all_caches()...
4
votes
3answers
4k 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 ...
3
votes
1answer
2k views

How to alter the path of login page?

I want to alter the path of login page, /user/login, to /ulogin. How can I accomplish this?
1
vote
1answer
59 views

How do I render a custom form on a view page?

In my module's routing.yml file I set the form path to a path which also shows a view page. But on that path the form does not get displayed, only the view. When I change the path in the routing.yml ...
5
votes
2answers
2k 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: ...
0
votes
1answer
58 views

How to hide menu item from high level roles but show for low level

I have 3 roles on site: anonymous user authenticated user admin I created a new page: function learning_menu() { $items = array(); $items['learning'] = array( 'page callback' =&...
0
votes
2answers
656 views

hook_menu() with enabled languages

I'm trying to implement hook_menu() in my module. The problem is, it doesn't add the menu item for English while it does for Turkish. I'm guessing it has something to do with title arguments, but I ...
2
votes
2answers
772 views

Can we have multliple routing.yml files in a single module?

I have more than 50 menus which I need to create custom. as per the module structure, we need to create routing.yml in root folder. but i want to do something like this below myModule - ...
1
vote
1answer
919 views

Disable menu cache for hook_menu() implementation

There is a way to disable the menu cache ? Context Drupal 7 I have a custom module that implements hook_menu(). The link is showing up only if a view have results. It's working. The problem is ...
0
votes
2answers
206 views

Menu alter for a particular content type

I am trying to add a custom access callback for the node edit page for a particular content type. I am using alterRoutes function to change the access callback but I am unable to get the node type ...
0
votes
1answer
256 views

Route restrict access for current user

How do I restrict access to the route by current user in Drupal 8? I want to create a new tab in user profile path: '/user/{user}/my-cool-tab', which should be accessible by current user only. For ...
0
votes
1answer
39 views

Cannot create hook_menu subitems with proper position in administrative menu

I would like to add an hook_menu item and generate its expandable subitems under ubercart's 'admin/store/' path. For now I have: function activit_menu() { $items['admin/store/products-fabrics'] =...
8
votes
1answer
2k 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 (!...
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\...
0
votes
1answer
128 views

Redirect to default node url

I have an question about drupal's redirect. Well I implemented hook_menu for the path: "node/%node/boost". And I set all callbacks from default node path: "node/%node". /** * Implements hook_menu()...
1
vote
1answer
61 views

How to only define hook_menu path to certain URL [duplicate]

Consider this simple implementation of hook_menu() /** * Implements hook_menu(). */ function helloworld_menu() { $items['hello'] = array( 'title' => 'Hello world!', 'page callback' =&...
0
votes
2answers
712 views

Why aren't my local tasks shown?

I have the module.routing.yml as entity.node.ssl_check: path: '/node/{node}/check-ssl' defaults: _form: '\Drupal\ssl_check\Form\SslCheck' _title: 'Check SSL Cert' requirements: ...
2
votes
1answer
793 views

Generating arbitrary internal URLs

I'm generating the URL inside a controller in a custom module. The URL I generate is to pages on the same site, but not in the module. I want to append an arbitrary number of slugs to the end of the ...
0
votes
1answer
465 views

Config Entity list_builder controller path throws Route Does Not Exist error

I have created a custom config entity, which declares a list_builder controller to return a list of the created entities. Before creating a config entity, it renders as expected. Once I create a ...
0
votes
1answer
28 views

Route logged in user to profile on all request to <front> node

I'm attempting to make a simple login page on the front page that once you log in it will route you to your profile. This part I got working with Rules, but if the user clicks the home link on the ...
1
vote
1answer
108 views

Why does hook_menu() not show my items in menu? [closed]

Here's my code and I can't get why hook_menu doesn't work. My block menu doesn't showing in menu. As I understood this code (hook_menu()) should show link in which for will work drupal_post_form using ...
6
votes
2answers
194 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....
0
votes
2answers
316 views

How do I change page callback for a particular menu?

There is already a menu defined in core module. I need to alter the page callback of this menu in another module. Similar to using hook_menu_alter() in Drupal 7, but since there is no hook_menu_alter()...
2
votes
2answers
495 views

Limiting access by role

So I basically have a custom module created and I just want to know how I can limit the users who can access the 2 forms I have by predefined roles -- the IT and Facilities roles that I have defined ...
1
vote
1answer
35 views

View menu routes missing until first page load

I having an issue with the installation logic of a custom module. I am trying to add menu links using menu_link_save() that link to a view that is defined in my module in hook_views_default_views(). ...
0
votes
3answers
58 views

How do I limit the access basing on the user role?

How do I use an access callback to limit the access basing on the user role? For example, in my site I have the following roles: Administrator Authenticate User Anonymous user Teacher I want to ...
1
vote
3answers
3k views

How to get node url of selected language?

I have a node with an array of multiple languages. [19] => Drupal\node\Entity\Node Object ( [in_preview] => [values:protected] => Array ( ...
1
vote
1answer
35 views

Where are {image_style} and {scheme} coming from?

I can't find much documentation on this subject other than https://www.drupal.org/node/2122201. This leads me to think that the subject is either much easier than I think, and doesn't have ...
4
votes
1answer
4k views

Get information about a menu item

In Drupal 8, you can use system blocks to show menus starting from different levels. For example: Menu item 1 (level1) --- Menu Item 2 (level2) --- Menu Item 3 (level2) Menu item 4 (level1) --- Menu ...
0
votes
0answers
25 views

<front> and <none> path are sync. with a view path

by default, front and none path is defined in the system.routing.yml file and it's '/'. But me, this value is sync with one of my view path. For exemple, in my page view "Xyz", if the path is "/x-y-...
1
vote
1answer
627 views

Is it possible to include a forward slash in a route dynamic property?

Is it possible to include forward slashes in routing parameters? // routing.yml mymodule.route path: '/mymodule/{param}' defaults: path: '' requirements path: '[A-Za-z0-9\-...
2
votes
0answers
284 views

Taxonomy name as path parameter

In my module, I have defined the following route: custom_module_page: path: 'new/post/{term-id}' defaults: _controller: '\Drupal\mymodule\Controller\myModuleArticleController::content' ...
0
votes
0answers
27 views

Route cannot be accessed

I have declared my permissions in hook_permissions(). function myid_permission() { return array( 'input_id' => array( 'title' => t('Input an ID'), '...