Allow altering the redirect URL upon success

Created on 25 December 2023, 11 months ago
Updated 26 January 2024, 10 months ago

Problem/Motivation

I have a requirement to redirect based on the user's role. Therefore, allow the alteration of the redirect URL upon success.

Feature request
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

🇻🇳Vietnam linhnm

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

Comments & Activities

  • Issue created by @linhnm
  • Status changed to Needs review 11 months ago
  • 🇻🇳Vietnam linhnm

    Change the hook after generate the URL

  • Status changed to RTBC 11 months ago
  • 🇦🇷Argentina tguerineau

    Hi,

    I have conducted testing, in drupal 10, on the patch submitted: allow-altering-the-redirect-url-success-3410776-3.patch. Here are the details of my testing process and findings:

    Setup and Configuration:

    • Applied the provided patch to the multi_domain_login module.
    • Configured the module settings.
    • Tested with various user roles, including Editor and Administrator.

    The patch works as intended, successfully allowing the alteration of the redirect URL based on user roles. The implementation aligns well with Drupal's hook system and provides the desired flexibility for redirecting users post-login, based on their roles.

  • Status changed to Postponed: needs info 10 months ago
  • 🇧🇪Belgium kriboogh

    There is already a possibility to alter the url right before the redirect happens using:

    function my_module_multi_domain_login_url(&$url, &$domain) {
      // Alter $url here.
    } 
    

    If you need more control, it is also possible to write a configuration override in your custom module and make it cache dependent on the user.

    namespace Drupal\my_module\Config;
    
    class MyModuleOverrides implements ConfigFactoryOverrideInterface {
    
      /**
       * {@inheritdoc}
       */
      public function loadOverrides($names) {
        $overrides = [];
        if (in_array("multi_domain_login.settings", $names)) {
          // Do custom stuff here to determine the $url.
          $overrides["multi_domain_login.settings"] = [
            'redirect_success' => $url,
          ];
        }
    
        return $overrides;
      }
    
     /**
       * {@inheritdoc}
       */
      public function getCacheableMetadata($name) {
        $cache = new CacheableMetadata();
        $cache->setCacheContexts(['user']);
        return $cache;
      }
    
    

    If this could suit your needs, please close this ticket or reset to "needs work" than we will look into it.

Production build 0.71.5 2024