Questions tagged [routes]

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

Filter by
Sorted by
Tagged with
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
224 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
140 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
81 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
839 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
262 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
131 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' ...
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 ...
3
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
88 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
62 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
38 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
837 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 ...
1
vote
2answers
3k views

How to override the menu_tree without affecting the admin menus

I've worked out how to override theme_menu_tree() using this code in template.php. function myTheme_menu_tree($variables) { return '<nav class="menu">' . $variables['tree'] . '</nav>'; }...
1
vote
2answers
977 views

How to programmatically add menu for content type?

E.g. article has main menu as default, I want to add (and remove) second menu as available to article content type in my unit tests, how can I do it?
0
votes
1answer
183 views

Show/hide menu link based on changing custom $tempStore value

I'd like to show/hide a main-menu link based on a $tempStore variable the user can set and modify during their session, i.e. user sets $tempStore['vlaue'] = 0; --> menu link is hidden user sets $...
1
vote
1answer
199 views

Default entity ID for _entity_view in routing.yml

I've a custom content entity (created using Config pages module) which is used as a welcome screen / dashboard. Privileged super editors can edit those content entities, normal editors can only view ...
0
votes
4answers
6k views

Expand sub-menus on hover in a menu block

I need to show menus expanded in the sidebar. I used the menu blocks to show the submenus. But now the problems is when I hover on the parent menu initially it is not showing the submenus which was ...
0
votes
1answer
587 views

How to add a default controller to the <front> route?

Is it possible to add a default controller to the '<front>' route? There's no default controller defined in system.routing.yml. I'm trying to get a handle on it by using the following code: &...
0
votes
0answers
101 views

Custom ParamConverter doesn't work (doesn't give error but return isn't what it should)

I'm learning Drupal8 (for the first time, no Drupal7 or previous knowledge) on a local Vagrant VM and have come up against this little problem. I'm sorry if it's kind of a noob question but I wasn't ...
0
votes
2answers
1k views

Display main menu expanded in footer, drop down in header

I'm trying to show the Main menu in two places, once as a dropdown menu at the top, then again in the footer as a fully expanded (non-collapsible) set of links. I'm using the Superfish module to ...
0
votes
2answers
44 views

What can Menus do that Taxonomy cannot?

'Comments', 'Users', 'Taxonomy' are Entity Types because they each define their own sets of required fields. I am having a discussion with my boss where I am arguing that 'Menu' are really just a ...
1
vote
1answer
493 views

Custom route using access check error with arguments

I have a custom route that needs to check if a user can create a certain group_node:article content inside a group (from the group module 8.x-1.0-rc2). The setting is as follows: mymod.routing.yml ...
1
vote
1answer
273 views

Can I get Entity Cache Tags from a Route?

If I have a node object I can use $node->getCacheTags() to get the cache tags for the node object, and I can do the same for other entities. Is there a way for me to do something similar with a ...
0
votes
1answer
334 views

Use JSON instead HTML for access denied on some custom paths

I create a small API for one project using Bathic Authentication. The API consists of some custom paths defined in routes in a custom module. Using JsonResponse() in the controller we send back a JSON ...
2
votes
1answer
162 views

Why is my custom parameter converter class not used?

I start banging my head on the table, the wall or anything else... please help me. Here is my my_module.routing.yml: my_module.api.validate_coupon: path: '/api/v1/{coupon_code}/validate' ...
0
votes
1answer
33 views

How to redirect to a specifi page of a view?

Here is the code of a custom form: public function save(array $form, FormStateInterface $form_state) { $entity = $this->entity; $status = parent::save($form, $form_state); $values=$...
1
vote
4answers
4k views

Does anyone knows a good menu module? [closed]

I'm looking for a menu module which would show a menu tree like: Menu level 1 (Container) |-------Menu level 2 |-------Menu level 2 |-------Menu level 2 |-------Menu level 2 |-----...
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 ...
2
votes
1answer
70 views

Is it possible or/and how to restrict access to the block on th certain page using route name?

I am trying to restrict access to the block to be accessible only on the route:entity.user.canonical route. Is it possible to define that on the block edit form?
3
votes
1answer
3k views

How to return JSONP from a menu callback

I can create JSON output using a menu hook using the drupal_json_output callback. Example: $items['page/%/json'] = array( 'access callback' => TRUE, 'page callback' => '...
0
votes
2answers
102 views

Show url attibuts in twig

I have this in my routing page function_adh_apport.adh_apport: path: '/collecte/apports/{date}' defaults: _controller: '\Drupal\function_adh_apport\Controller\RapportsController::filtrer' ...
2
votes
1answer
3k views

Correct way to use hook_menu_alter

What is the correct way of using hook_menu_later. I did this in my module to redirect (see also redirect in hook_init makes body text disappear): function MYMODULE_menu_alter(&$items) { $items[...
1
vote
2answers
677 views

How do I convert hook_menu()? [closed]

I am having site built in Drupal 7 and in future I want to migrate my site to Drupal 8. How can I write hook_menu() and hook_menu_alter() to routing.yml files?
0
votes
1answer
261 views

Menu access callback function called multiple times

I have following menu defined with access callback function. As You can see this is a hack so I can use REST via GET ( normally Services do not offer this ). All my endpoints are defined /rest/api/[...
3
votes
2answers
1k views

how to restrict access in routing.yml based on roles

I know how I to restrict access in the routing.yml file based on permissions, but how can I do it based on roles? This is how to do it by permissions: requirements: _permission: 'access ...
2
votes
0answers
277 views

Detail page route gives error

In my_module.routing.yml my_module.detail: path: '/module/{id}' defaults: _controller: '\Drupal\module\Controller\DetailController::view' requirements: _access: 'TRUE' In template twig ...
1
vote
1answer
53 views

Can a Event Service be coupled to a route

I have created a custom service and have hooked into the "event_subscriber" via tags in my custom service.yml demo_api.exception_handler_subscriber: class: Drupal\demo_api\Response\Handler ...
0
votes
1answer
21 views

Externally Requesting Browser Test Created URL for Relaxed Replication

I am trying to write a browser test for for a workspace replication via relaxed web services using the multiversion, replication and relaxed modules. For this purpose I set up an external Drupal ...
2
votes
2answers
487 views

How do I print a menu with links generated by my custom module?

If I use theme('links', array('links' => menu_navigation_links('main-menu'), 'attributes' => array('class'=> array('links', 'main-menu')) )); It will print the links in my Main Menu. I need ...
2
votes
1answer
95 views

Why is my form only redirected sometimes?

I want to have a user register, and be redirected to a node create form. Here's how I'm doing it thus far. The setup I have a route, my_module.register that is handled by MyController::register(). ...
0
votes
1answer
295 views

Multiple aliases per node (and active trail)

Our site is split down the middle for tenants and landlords. But we have content the is the same for both such as "how to report antisocial behaviour". User would normally navigate something like "...