Allow other modules to prevent redirection (e.g. Commerce)

Created on 4 March 2021, almost 4 years ago
Updated 2 April 2024, 9 months ago

Problem/Motivation

The hook after_user_login is preventing the customer to be redirected when he making an order.

Steps to reproduce

Install Commerce.
Make an order from anonymous user, register and continue while making the order -> redirected to the homepage instead of checkout pane.

Proposed resolution

Include the route of commerce order to ignore when redirecting after login in hook.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

RTBC

Version

3.0

Component

Code

Created by

🇨🇭Switzerland Ginovski Bern

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India prempatel2447 Varanasi

    Hi Everyone,

    We will include all the changes in new release with Drupal 10 compatibility.

  • Pipeline finished with Skipped
    over 1 year ago
    #18022
  • Pipeline finished with Success
    about 1 year ago
    Total: 183s
    #24452
  • Pipeline finished with Failed
    about 1 year ago
    Total: 58s
    #41731
  • Pipeline finished with Failed
    about 1 year ago
    Total: 230s
    #50495
  • First commit to issue fork.
  • 🇨🇭Switzerland pvbergen

    pvbergen changed the visibility of the branch 3201520-integration-with-commerce to hidden.

  • 🇨🇭Switzerland pvbergen

    The changes haven't made it into 2.x or 3.x yet. Updated the issue and MR for 3.0.x.

  • Pipeline finished with Success
    about 1 year ago
    Total: 194s
    #56594
  • Pipeline finished with Skipped
    about 1 year ago
    #59700
  • Pipeline finished with Success
    about 1 year ago
    Total: 174s
    #66873
  • Pipeline finished with Success
    12 months ago
    Total: 161s
    #69573
  • Pipeline finished with Success
    12 months ago
    Total: 253s
    #70958
  • Pipeline finished with Failed
    12 months ago
    Total: 171s
    #71797
  • Pipeline finished with Failed
    11 months ago
    Total: 905s
    #79625
  • Pipeline finished with Failed
    11 months ago
    #81415
  • Pipeline finished with Failed
    11 months ago
    #81428
  • Status changed to Needs work 11 months ago
  • 🇧🇬Bulgaria pfrenssen Sofia

    Instead of adding more routes to the list, it would be a better idea to dispatch an event that can prevent the redirection. That would fix the problem for all possible use cases.

  • Pipeline finished with Success
    11 months ago
    Total: 138s
    #84403
  • 🇧🇬Bulgaria pfrenssen Sofia

    I added a new MR that dispatches an event allowing any module to prevent redirection, or alter the redirection URL.

    To prevent redirection on the Commerce checkout form, a subscriber can be implemented that checks the route:

    <?php
    
    declare(strict_types=1);
    
    namespace Drupal\ekw_test\EventSubscriber;
    
    use Drupal\Core\Routing\RouteMatchInterface;
    use Drupal\redirect_after_login\Event\RedirectAfterLoginEvent;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    /**
     * Subscribes to the RedirectAfterLoginEvent.
     */
    class MySubscriber implements EventSubscriberInterface {
    
      /**
       * Constructs a MySubscriber object.
       *
       * @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
       *   The current route match.
       */
      public function __construct(
        protected RouteMatchInterface $routeMatch,
      ) {}
    
      /**
       * Prevent redirect after login in the Commerce checkout.
       */
      public function onRedirectAfterLogin(RedirectAfterLoginEvent $event) {
        $current_route = $this->routeMatch->getRouteName();
        if ($current_route === 'commerce_checkout.form') {
          $event->setRedirectAllowed(FALSE);
        }
      }
    
      /**
       * {@inheritdoc}
       */
      public static function getSubscribedEvents() {
        return [RedirectAfterLoginEvent::class => 'onRedirectAfterLogin'];
      }
    
    }
    
  • Pipeline finished with Success
    10 months ago
    Total: 233s
    #95274
  • Pipeline finished with Success
    10 months ago
    Total: 139s
    #96807
  • Pipeline finished with Canceled
    10 months ago
    Total: 129s
    #97154
  • Pipeline finished with Failed
    10 months ago
    Total: 211s
    #97355
  • Pipeline finished with Success
    10 months ago
    Total: 142s
    #106249
  • Pipeline finished with Failed
    10 months ago
    #117553
  • Pipeline finished with Failed
    10 months ago
    Total: 156s
    #117596
  • Pipeline finished with Failed
    10 months ago
    Total: 174s
    #117614
  • Pipeline finished with Failed
    9 months ago
    Total: 238s
    #124745
  • Pipeline finished with Success
    9 months ago
    Total: 218s
    #125185
  • Pipeline finished with Success
    9 months ago
    Total: 162s
    #128716
  • Pipeline finished with Failed
    9 months ago
    Total: 186s
    #130558
  • Pipeline finished with Success
    9 months ago
    Total: 167s
    #131308
  • 🇨🇦Canada phjou Vancouver 🇨🇦 🇪🇺

    Works perfectly @pfrenssen thanks!

    I had to use this on the "auto_login_url.login" route otherwise it was breaking the auto login url module.

  • Status changed to RTBC 9 months ago
  • 🇨🇦Canada phjou Vancouver 🇨🇦 🇪🇺
  • Pipeline finished with Success
    9 months ago
    Total: 190s
    #138932
  • Pipeline finished with Failed
    9 months ago
    Total: 90s
    #142880
  • Pipeline finished with Success
    8 months ago
    Total: 186s
    #146655
  • Pipeline finished with Failed
    8 months ago
    Total: 400s
    #148550
  • Pipeline finished with Failed
    8 months ago
    Total: 185s
    #151898
  • Pipeline finished with Success
    8 months ago
    Total: 152s
    #156483
  • Pipeline finished with Success
    8 months ago
    Total: 304s
    #162570
  • Pipeline finished with Failed
    8 months ago
    Total: 215s
    #163134
  • Pipeline finished with Success
    8 months ago
    Total: 193s
    #163160
  • Pipeline finished with Success
    8 months ago
    Total: 146s
    #165848
  • Pipeline finished with Success
    8 months ago
    #165851
  • Pipeline finished with Failed
    8 months ago
    Total: 290s
    #166855
  • Pipeline finished with Success
    8 months ago
    Total: 140s
    #167176
  • Pipeline finished with Success
    8 months ago
    Total: 138s
    #170765
  • Pipeline finished with Failed
    7 months ago
    Total: 78623s
    #174562
  • Pipeline finished with Skipped
    7 months ago
    #175760
  • Pipeline finished with Failed
    7 months ago
    Total: 178s
    #176714
  • Pipeline finished with Success
    7 months ago
    Total: 391s
    #177228
  • Pipeline finished with Success
    7 months ago
    Total: 148s
    #183800
  • Pipeline finished with Canceled
    7 months ago
    #184003
  • Pipeline finished with Failed
    7 months ago
    Total: 165s
    #184975
  • Pipeline finished with Failed
    7 months ago
    #185323
  • Pipeline finished with Success
    7 months ago
    #189366
  • Pipeline finished with Canceled
    6 months ago
    Total: 41s
    #202813
  • Pipeline finished with Success
    6 months ago
    Total: 223s
    #207140
  • Pipeline finished with Success
    6 months ago
    Total: 204s
    #210624
  • Pipeline finished with Skipped
    6 months ago
    #213853
  • Pipeline finished with Canceled
    6 months ago
    Total: 88s
    #216773
  • Pipeline finished with Success
    6 months ago
    Total: 893s
    #217520
  • Pipeline finished with Failed
    5 months ago
    Total: 180s
    #226351
  • Pipeline finished with Success
    5 months ago
    Total: 176s
    #232271
  • Pipeline finished with Success
    5 months ago
    Total: 143s
    #246735
  • Pipeline finished with Success
    5 months ago
    #247701
  • Pipeline finished with Success
    5 months ago
    Total: 447s
    #248204
  • Pipeline finished with Success
    4 months ago
    Total: 222s
    #256008
  • Pipeline finished with Success
    4 months ago
    Total: 156s
    #262975
  • Pipeline finished with Success
    4 months ago
    #263416
  • Pipeline finished with Failed
    4 months ago
    Total: 178s
    #267698
  • Pipeline finished with Canceled
    4 months ago
    Total: 75s
    #269357
  • Pipeline finished with Failed
    4 months ago
    Total: 237s
    #269858
  • Pipeline finished with Success
    4 months ago
    #273524
  • Pipeline finished with Success
    4 months ago
    Total: 167s
    #277296
  • Pipeline finished with Failed
    4 months ago
    #278499
  • Pipeline finished with Success
    3 months ago
    Total: 142s
    #283163
  • Pipeline finished with Success
    3 months ago
    Total: 228s
    #286420
  • Pipeline finished with Failed
    3 months ago
    Total: 235s
    #292068
  • Pipeline finished with Failed
    3 months ago
    Total: 1714s
    #292079
  • Pipeline finished with Failed
    3 months ago
    Total: 298s
    #302177
  • Pipeline finished with Failed
    3 months ago
    Total: 180s
    #302379
  • Pipeline finished with Success
    2 months ago
    Total: 211s
    #310282
  • Pipeline finished with Running
    2 months ago
    #310808
  • Pipeline finished with Failed
    2 months ago
    Total: 76s
    #312460
  • Pipeline finished with Success
    2 months ago
    Total: 132s
    #313758
  • Pipeline finished with Success
    2 months ago
    Total: 146s
    #314097
  • Pipeline finished with Success
    about 2 months ago
    Total: 161s
    #321011
  • Pipeline finished with Success
    about 2 months ago
    Total: 147s
    #321351
  • Pipeline finished with Failed
    about 2 months ago
    Total: 95s
    #321882
  • Pipeline finished with Success
    about 2 months ago
    Total: 158s
    #323166
  • Pipeline finished with Skipped
    about 2 months ago
    #324045
  • Pipeline finished with Success
    about 1 month ago
    Total: 157s
    #335331
  • Pipeline finished with Success
    about 1 month ago
    Total: 180s
    #337635
  • Pipeline finished with Failed
    about 1 month ago
    #337875
  • Pipeline finished with Success
    about 1 month ago
    Total: 140s
    #347036
  • Pipeline finished with Failed
    30 days ago
    Total: 179s
    #348967
  • Pipeline finished with Failed
    29 days ago
    Total: 180s
    #350036
  • Pipeline finished with Canceled
    29 days ago
    Total: 97s
    #350181
  • Pipeline finished with Success
    29 days ago
    Total: 148s
    #350185
  • Pipeline finished with Failed
    23 days ago
    Total: 148s
    #355915
  • Pipeline finished with Failed
    20 days ago
    Total: 251s
    #359266
  • Pipeline finished with Failed
    19 days ago
    Total: 214s
    #360247
  • Pipeline finished with Success
    15 days ago
    Total: 128s
    #363122
  • Pipeline finished with Success
    14 days ago
    Total: 140s
    #364338
  • Pipeline finished with Success
    8 days ago
    Total: 170s
    #370520
  • Pipeline finished with Success
    6 days ago
    Total: 260s
    #373197
  • Pipeline finished with Success
    1 day ago
    Total: 204s
    #377159
Production build 0.71.5 2024