Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I want to redirect all users but the admin to the Web File Manager.
For this reason I have set the destination path field (Always) to "webfm".
The Redirect condition field I have set to "PHP snippet" and entered the following code:
global $user;
return ($user->uid != 1);
Despite this setting also the admin (uid=1) user is always redirected to "webfm" after login.
What have I done wrong?
Thanks for any help.
Christian
Comments
Comment #1
nathan573 CreditAttribution: nathan573 commentedThe problem here seems to be that at the time the redirection condition php snippet is run the user is still perceived by Drupal as anonymous. I found this out by sending myself an email with the output of the $user array from the redirect condition php snippet. The redirect condition would be a lot more useful if it had access to the user info for the user that is logging in. I'm not sure if there is an easy work-around. Dmitry, do you have any ideas for us? Thank you.
Comment #2
nathan573 CreditAttribution: nathan573 commentedThe work around for this is to put all the logic in the "URL destination settings" php snippet. Set the "Redirection condition" to "Always" and then create the php snippet that defines the path taken upon login.
Here's a snippet I use to redirect a user to a terms page if they don't already have a variable set indicating they've agreed to the terms, otherwise I take them to their user page.
Comment #3
ddrozdik CreditAttribution: ddrozdik as a volunteer commentedVersion 5 of the module is not supported anymore.