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.

1
vote
1answer
551 views

How do I create a route that is specific for a subdomain?

I'm looking to create a "subdomain" path to my custom controller running on a Drupal 8 site, with routing and hopefully without the need for an additional module. The idea is to for example have a ...
3
votes
1answer
620 views

Custom configuration forms: translation access denied

While creating custom configuration forms, I'm getting an access denied. But on the /translation page of the form only. Configuration form itself can be reached, filled and updated without problems. ...
2
votes
1answer
568 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 ...
4
votes
1answer
508 views

Create a path to node/add in twig

Can I use the path() function in twig to create a link to a non-node entity add form. Taking the group module as an example, if I want to create a link to the 'group/add' page in twig can I use ...
0
votes
1answer
236 views

How do I dynamically change an autocomplete route for a field depending on another field's value?

On my node edit form, I have a select field (Field A) and another taxonomy reference field (Field B). Field B is currently using "views" as a reference method to filter for the options. When the ...
5
votes
3answers
2k 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\...
0
votes
1answer
617 views

How to add query parameters to a CacheableJsonResponse's cache?

I have an API which returns various json, like terms of a vocab, nodes of a type, with specific fields and so on. Now, in my API I am getting the requested language like so: $request = \Drupal::...
0
votes
1answer
476 views

How to get current route in the midst of a Views AJAX request

I need to conditionally pass contextual filter values to a view based on the current route and am attempting to do so in hook_views_pre_view. This is the result of using AJAX via views_infinite_scroll ...
2
votes
1answer
739 views

Defining module.links.action.yml with route parameters

How can I pass dynamically route parameters to module.links.action.yml? My code of module.links.action.yml: module.group_apply: route_name: module.group_apply title: 'Subscribe to group' ...
0
votes
1answer
29 views

hook_menu() doesn't work as expected. How can I fix that?

hook_menu() contains the following code. //案件 > インポート設定 > GMC_Subaccountの追加 $items[FEED_MANAGER_MENU_PATH.'/import/%import_id/gmc_subaccount/add'] = array( 'title' => 'GMCサブアカウントの追加', ...
0
votes
1answer
69 views

conceptual question about updating GET url

I am sorry if this question was asked before, but I am getting hard time with a concept of changing url parameters that was created by GET form in Drupal 8. Here what I have done so far and what I ...
0
votes
0answers
2k views

Pass custom variable to twig

I have a custom router and in Controller of my route I do some works after that I want to pass my custom variables to twig theme,I did it simple on Symfony but it seems the Symfony mechanism not ...
5
votes
1answer
489 views

Providing menu route parameter values from url

Suppose I have the following route in my ej.routing.yml file: ej.form.user.profile: path: '/user/{user}/ej_profile' defaults: _title: 'EJ Profile' _form: '\Drupal\ej\Form\User\ProfileForm' ...
2
votes
0answers
56 views

Why would routes lose their aliases?

I have experienced this twice now on a Drupal 8 site. Pathauto is at its current version and Drupal is 8.2.6. What is happening is sometimes nodes 'lose' their aliases and revert back to being node/...
3
votes
1answer
3k 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 ...
3
votes
1answer
499 views

Change the URL of a node based on parent path

So let's say I have a basic page node. I want to have this as an entity reference inside another content type - let's say an event content type. So let's say that the event content has a url like ...
1
vote
1answer
2k views

Disable caching on a route

I have a route with a parameter, e.g. /r/{app_id}. The controller extends ContainerInjectionInterface. The method either returns a render array or a new TrustedRedirectResponse. I believe I have a ...
0
votes
1answer
145 views

Creating Custom Modules tutorial doesn't work - help! [closed]

I'm trying to teach myself how to create a custom module using Drupal 8, and followed the instructions on their website at this Drupal.org documentation page I created the folders, hello_world.info....
1
vote
1answer
421 views

Alternate of using “delivery callback”

$items['mymodule/%user'] = array( 'title' => 'My Module', 'page callback' => 'mymodule', 'page arguments' => array(1), 'access arguments' => array('access user profiles'), 'type' ...
0
votes
1answer
3k views

How do I call a controller method from a twig template and passing arguments to it?

I know I can pass variables to templates using render arrays. $theme = 'block-AcademicDisplay'; return array( '#theme' => $theme, '#content' => $content, '#url' => urlencode($url), ...
2
votes
2answers
2k views

how to create a route with query string?

I have tried a few things and I cannot manage to make this working. My route is the following. amu_hal.publicationsPerYear: path: '/publications/{year}' defaults: _controller: '\Drupal\...
0
votes
0answers
58 views

route not working when using encoded url as upcast parameter

my route amu_hal.publicationsPerYear: path: '/publications/{year}/{url}' defaults: _controller: '\Drupal\amu_hal\Controller\AmuHalController::publicationPerYear' _title:...
1
vote
1answer
347 views

Convert view route parameter to entity

Task: Create a view with link to it displayed among node tabs (View, Edit, etc.). Solution: Create a view with page display and set its path to "node/%node/foo". Issue: When the page "node/%node/foo"...
1
vote
0answers
19 views

User is able to see a inaccessible link

I had created menu link using hook_menu $items['admin/config/xyz'] = array( 'title' => 'xyz Webservice Settings', 'description' => 'Configures the xyz Settings', 'page callback' =&...
1
vote
0answers
34 views

How do I make custom pages? [closed]

I have a custom form with a custom schema. The schema has an ID that auto increments. Now I want to show the content on custom pages; each id should have its own page. What I want to do is if I'm ...
1
vote
0answers
441 views

Link to user edit form within a GUI made menu

I have a menu created through admin/structure/menu. I would like to add a link to the logged in users edit profile. I am attempting to do this via module.links.menu.yml but it is not working. The ...
2
votes
1answer
42 views

How to remove empty div created by routing.yml file by specified routes?

I have 2 routes games.one: path: '/math/one' defaults: _controller: '\Drupal\games\Controller\GamesController::one' _title: 'My Title' requirements: _permission: 'access content' ...
1
vote
1answer
248 views

How do I use non-admin theme for page containing node form? [closed]

I've created a custom route where I return node add form with a controller. It works fine, but for the administrator user it is using the administrator theme. I tried using the following, but it ...
3
votes
1answer
348 views

How to pass a custom object from a page to another page through a route or other means?

I want to be able to pass a custom object of type FormMode through a route or any other way. My custom.routing.yml file is: custom.page: path: '/custom/{model}' defaults: _controller: '\...
3
votes
2answers
656 views

Create a general rewrite rule in .htaccess [closed]

In an upgrade scenario I have to provide some alias URLs like www.server.com/reading_23.html that should actually deliver www.server.com/reading/23. I spent lots of hours trying to make that work by ...
0
votes
0answers
247 views

Routing Parameter Directly Passed And Upcast

Has anyone come across a way to both pass a dynamic route parameter as well as upcasting it? something like: /module/custom/mymodule/src/Routing/MyRoutes.php $routes["my.custom.route"] = new Route( ...
1
vote
2answers
669 views

Routing match everything

i want to match in a route a 'random' URL with a random sub path, fox example: /example/1/a/b/c /example/c3/s ... i implement this route in my .routing.yml file modulo.validator: path: '/example/...
1
vote
2answers
2k views

How do I pass a URL to a route?

I need to send the URL of a Drupal 8 route to a template. I read some documentation on Drupal API, but when I implement this in my module, nothing happens. My route in my routing file looks like the ...
1
vote
1answer
142 views

hook_menu wildcard auto-loader for webform submission?

In hook_menu() array keys, you can specificy wildcard tokens to autoload certain objects, such as %node to get the node object. Is there a wildcard autoloader token for webform submissions? Some ...
1
vote
1answer
94 views

Error 500 when including controller file in Route [closed]

I am trying to upgrade a mailing list from drupal 7 to 8. I am getting an 500 error when I include my controller in the route file. I checked the path in both route and controllers and almost tried ...
1
vote
1answer
4k views

How to display a block with menu child items programmatically?

I need to create block with a list of links menu child items (only first level) of a given menu like this: Item 1 Item 2 Item 3 With this code I can have the menu items but I don't know how to ...
1
vote
1answer
517 views

Open Menu Link In New Browser Tab/Window

I am having a problem with opening a menu link defined in a module.links.menu.yml in a new browser tab or window. Code for the link: mymodule.mm_google: url: 'https://google.com/' parent: ...
-1
votes
1answer
34 views

Changing the routing class is throwing an error

I am trying to change my UserLoginForm class to iLibUserLoginForm with the following code. namespace Drupal\ilib_sso\Routing; use Drupal\Core\Routing\RouteSubscriberBase; use Symfony\Component\...
2
votes
1answer
41 views

hook_form_alter or overriding the routing and UserLoginForm class

I am trying to add another mechanism for login into Drupal (adding an SSO function which would validate based on some criteria that a third party system will provide to Drupal). I am trying to decide ...
1
vote
1answer
344 views

How to change autocomplete_route_parameters value on change of select option?

How to change autocomplete_route_parameters value on change of select option? I have a form element and inside autocomplete_route_parameters, I want to change $langcode value when I select any ...
1
vote
3answers
53 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 ...
11
votes
5answers
8k 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 ...
2
votes
1answer
410 views

How to solve a situation where two or more routes with different controllers point to the same path ?

For example, we have two routes, which points to the same path. And each route has its own controller. For example, I have defined a route with controller, which has a path "node/1", whereas a node ...
0
votes
1answer
49 views

Creating Routes to deal with a form

So I have created a block in which I've added a form, build with the form API. It contains a textfield and a submit button. My next step is to create a route that calls a method in a controller in my ...
14
votes
4answers
4k 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 ...
1
vote
0answers
96 views

Altering existing route in Drupal 8 [duplicate]

I am following this tutorial: Altering existing routes and adding new routes based on dynamic ones for changing the route from '/example' to '/example/helloworld'. I tried following code in my ...
6
votes
2answers
2k 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?
1
vote
2answers
513 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 ...
2
votes
1answer
2k views

How can I turn off Drupal redirect caching?

I have a url that would normally redirect to a specific page, however, some code is run prior to this. I am returning a RedirectResponse and it appears to be being cached. How can I force this to not ...
0
votes
1answer
53 views

How do you set a one-off access checker on a route?

As far as we can tell, the "Simplified custom access checker" section of the handbook is outdated. The entirety of CheckProvider seems to be service oriented and this is the provider which has the $...