Questions tagged [routes]

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

Filter by
Sorted by
Tagged with
2
votes
1answer
715 views

Get the language from route

Is there a way to get the language from a routeMatch in Drupal 8? E.g. if I do: $route_match = \Drupal::routeMatch(); Currently I can't find any language information in the returned object. It ...
1
vote
1answer
820 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\-...
0
votes
1answer
148 views

How to upcast webform submission in custom routes resp. controller?

Using this route: confirm: path: '/node/{node}/submission/{webform_submission}/confirm' defaults: _controller: '\Drupal\mymodule\Controller\MymoduleController::confirm' _title: 'Confirm ...
4
votes
2answers
967 views

Show menu link descriptions for a custom navigation menu

I have the following navigation, displayed in page.tpl.php: theme('links', array('links' => menu_navigation_links('menu-site-navigation'))); There are four navigation elements that show up. I ...
1
vote
3answers
2k views

Pass argument to custom access callback

Is there a way to specify an argument to pass to a custom access callback, specifically an argument that isn't part of the path? Like in Drupal 7 you could do this: function mymodule_menu() { $...
1
vote
1answer
1k 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
39 views

How do I add an anchor attribute to a route?

I've created a route: regions.taxonomy_term.edit_form_header: path: '/taxonomy/term/{taxonomy_term}/edit' defaults: _entity_form: 'taxonomy_term.default' _title: 'Edit term' options: ...
1
vote
3answers
1k views

routing.yml for a custom form not working [closed]

I have a form I'd like to use as a standalone page, which I'm defining in a module I've called "SREvent". I have created modules/srevent/src/Form/SREventListForm.php: <?php /** * @file * ...
6
votes
1answer
200 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['...
3
votes
0answers
56 views

When a path is associated to more routes, which route is used?

How does Drupal 8 decide which route to use, if there are two routes defined in Drupal 8 via routing.yml that lead to the same path? Of course this sounds like a stupid idea or like a mistake in code ...
0
votes
1answer
57 views

How to force 403 or 404 on specific route

I have made a custom form to create nodes for a specific content type. Due to that, I want to throw a 403 or 404 on the admin page that creates new node. The route I mean is 'node/add/'. I guess in ...
0
votes
0answers
39 views

Assign a controller to all book pages

I am trying to build a module that checks if user session set in all pages of a certain book. if the session is not set it will be set. I am using a sso system so the user data will come from there, ...
1
vote
1answer
504 views

How to redirect programmatically inside a module to an external url? [closed]

I am trying to redirect to a page after I unset a session. I read this article but I am pretty new to Drupal module building. Here this amazing guy says to do the comming thing: If you know that ...
1
vote
2answers
222 views

Using menus anywhere on page - how to stop them expanding by default when not used in menu region ( e.g. in a block or panel)?

I am trying this with superfish but the menu options are expanded by default. What would I need to do to get it to behave like it does in a menu (i.e. collapsed by default). I want to use the menu ...
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 ...
4
votes
1answer
271 views

Get route name from path with wildcard

we've wanted to implement a policy to consider some URLs as whitelist, I've provided a config form to admin to enter whitelist Urls, separated by newline, it must support * ( wildcard). sample urls ...
0
votes
3answers
286 views

PHP Warning SplObjectStorage::offsetExists() expects parameter 1 to be object, null given

Updating to 8.5.1 today from 8.4.5, and after a successful update, I start getting the following warnings on every page: Warning: SplObjectStorage::offsetExists() expects parameter 1 to be object, ...
0
votes
1answer
1k views

hook_menu_local_tasks_alter for specific tab

I've tried with my custom module to implement hook_menu_local_tasks_alter, but I'm not sure how can I edit specific tab. Here's my example code: <?php function ...
1
vote
1answer
32 views

Set access restriction for baseroute

Let's say I have the following in example.links.task.yml from a contributed module: example.view: title: 'View' base_route: 'entity.example.canonical' route_name: 'entity.example....
1
vote
2answers
632 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 ...
0
votes
2answers
44 views

Missing argument 1 for hook_menu()

I'm getting this error in my custom module. [warning] Missing argument 1 for signin_menu(), called in /public_html/includes/menu.inc on line 2813 and defined signin.module:2 here is my code to ...
0
votes
2answers
506 views

Can I programmatically inject a route parameter?

In my projects I often have some special node (types), for which I'm creating custom admin routes and custom edit forms. E.g. I've got a restaurant homepage offering daily lunch specials. For ease of ...
8
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: { ...
0
votes
0answers
102 views

Is _access: 'TRUE' mandatory for a public route?

I want a route to be accesed by everyone (logged in or not). I removed the requirements and still I was seeing Access Denied. It worked only when I put _access: 'TRUE'. Why is this mandatory? Should ...
5
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?
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
0answers
32 views

Can I require a query string parameter?

In a route, say password_recover/?code=XXX How can I make codea required parameter? i don't have control over the system that appends the parameter to the url.
0
votes
2answers
72 views

Custom submit handler stops working when checking route

I'm trying to setup a custom submit handler, so I can change the redirect URL after submitting comments. Edit: I just want to send users back to the page they were viewing to begin with, but it's a ...
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\...
1
vote
1answer
188 views

How to get an entity create route, given an entity type and bundle?

I am the maintainer for Views Add Button: https://www.drupal.org/project/views_add_button , which creates a button (link with classes) in a Views header or footer, that allows the user to add content ...
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 ...
2
votes
5answers
1k views

Keep the destination argument in when user switch from user login to register?

I have a link for users to click so that they can add a specific node type, and I use a link like below so that if the user isn't logged in, he/she can login and then be redirected to the node form, ...
1
vote
0answers
122 views

How do I set a url query parameter node/{node}/edit for a specific content type?

I'm trying to add a taxonomy term from the node in question as a url parameter, but am struggling to figure out how to do it without just going through the site and modifying all of the links that ...
0
votes
1answer
31 views

disable translatable route object

I've developed a module which generates and displays dynamic content. The title of the page is also generated dynamically in the controller as show below: if ($route = $request->attributes->get(...
3
votes
4answers
2k views

How do I hide Bartik Main Menu on front page from unauthenticated users?

I have a private website in which content can only be viewed by authenticated users. All I want is the login box for non authenticated users. I am using NodeAccess and also Rules module to do this. ...
0
votes
0answers
74 views

Multiple front page aliases

This question may be simple and I'm overlooking the answer, but I am trying to add routes that are front page aliases and there doesn't seem to be an obvious solution. Basically what I want is to add ...
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/...
0
votes
1answer
656 views

How do I check if a user may access a given route?

I am trying to render a link from a Url object and verify the user actually has access to that URL, like when viewing a node. For some reason, this always returns FALSE, although the node is ...
1
vote
1answer
215 views

Redirect user from a custom access callback

In my module routing I have a custom access callback for a payment page. _custom_access: 'Drupal\mymodule\Form\PaymentForm::access' It checks if the user: is allowed to make the payment (it's their ...
1
vote
1answer
119 views

Parameter upcasting in Forms: buildForm works, submitForm doesn't

Route: mymodule.applications.payment_form: path: '/payment/{submission}' defaults: _form: '\Drupal\mymodule\Form\PaymentForm' _title: 'Pay Fee' requirements: _role: 'applicant' ...
3
votes
5answers
3k views

How do I filter a menu to only show menu items translated into current language?

In my Drupal 8 project I have a menu containing menu items in english. Some of the items have a german translation. How do I filter the menu to only show the german items when viewing the site in ...
2
votes
4answers
6k views

Adding a class to the <li> tag of a menu

I need to put a class/ID on the actual li element as each link in the menu has a color-coded background when active meaning, I can't just style ".active-trail" as that will be the same color for every ...
1
vote
3answers
54 views

Verify source of url call

In hook menu, there is a url that is used to be called by some gps device to register its lcoation in the database. Let say the url is sitename.com/gps/location/123.123/456.456 But I want to make ...
2
votes
2answers
1k views

How do I programmatically create a route?

I'm trying to create a route programmatically using this code. example.routing.yml route_callbacks: - '\Drupal\example\Routing\ExampleRoutes::routes' Drupal\example\Routing\ExampleRoutes.php ...
0
votes
1answer
84 views

How can a controller change the url reported to browser?

I have got two routes - one is for pausing mail jobs, the other one for listing them. When I click on "pause" - the pause route: does it's thing internally calls the list route with a couple of ...
0
votes
0answers
56 views

How to define caching for OutboundPathProcessor

I've got a customized OutboundPathProcesser that adds GET parameters to URLs starting from a specific node type targetting a specific node id. Basically whenever I'm on a node of type product, I add ...
0
votes
0answers
32 views

Create route with parameter as first argument [duplicate]

For version 3.x of simple_sitemap I need to be able to create a route where the first argument is a parameter: simple_sitemap.sitemap_variant: path: '/{variant}/sitemap.xml' ... The controller ...
1
vote
0answers
34 views

Hook menu in the page--front.tpl with a passed var

Given the url, for example: website/all I wish the hook_menu, to load the existing frontpage, currently using a page--front.tpl. passing the "all" arg to the page so I know I need to load all ...
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 ...
1
vote
2answers
745 views

Static Frontpage

I'm a seasoned front-end developer and extremely new to Drupal. I've just created a new instance of Drupal 8 and all I am trying to do is create a static one pager for a client who needs a simple web ...