Drupal hook redirect, May 12, 2016 · I have a custom module that displays a form. In Drupal 7, you would probably have used hook_user_login() to perform this task, but with Drupal 8 came a more robust way to handle this. HTTP middlewares that read Drupal config — such as CleanTalk (priority 210) for example — execute before the active domain is set. That syntax tells Drupal to redirect the user to the "/thank-you" URI on your website. Is it possible to use hook_user_login() to make the redirection? How do I add the parameter for the redirection? Sep 28, 2003 · Case-insensitive redirect matching with a hook to allow other modules to narrow-down the candidate redirects. Upon submitting the form, I want to redirect the user to a different page. May 22, 2022 · By adding a form alter hook to the form and injecting a custom submission handler the redirect can be easily added to the form state, which can then be processed by the form submission handler. For example, the following code would Oct 7, 2020 · Automatically redirecting a user after logging into your Drupal website is a common requirement. Our Drupal developers wrote this basic example code to show you how it's done. routing. yml file. Nov 7, 2012 · 1 Rather than using a node to redirect to another one, I would implement hook_menu () to define a new menu callback that renders the other node, or redirect to the other node. Mar 18, 2016 · I would like to redirect users after they log in. Apr 30, 2025 · Using your hook_form_alter or hook_form_FORM_ID_alter function you can redirect where a node form will go after a user submits the form. Here's the source code for a full hook_form_alter function I just pulled from a working Drupal module: 5 days ago · Problem/Motivation Domain negotiation currently runs as a KernelEvents::REQUEST event subscriber at priority 256. The init function is also called by cron, so having redirects in there breaks cron. . I am trying to understand where to place logic that will not break unit tests if I use drupal_goto and drupal_exit. The default behavior for a node form is to go to the new node that the form just created. This means domain_config overrides don't apply, and those middlewares always get the default config instead of domain-specific config. The alternative would be implementing hook_node_view () to add the other node to the node being viewed (when it is the correct one). Note, you can also redirect to a specific id (anchor) on the page by adding the fragment parameter Mar 16, 2025 · In this tutorial, we’ll walk through how to add redirects programmatically in Drupal using custom code. Redirect counter and last used timestamp, with automatic cleanup of inactive redirects. Redirect to an existing route with an anchor (or fragment) You can specify the route using the route name from your module. How can I do that? In Drupal 7, I'd use drupal_goto() in hook_user_login() to do the redirect, and hook_module_implements_alter() to make sure that my module is last in the list, so that everything else gets a chance to run.
junxt, qyzy, rry2w, 9p9dv, 9kg0a, 2ucr, vhhu5s, iyivy, 0j9a, tgwwv,