New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multilingual: Correcting login redirect #12932
Multilingual: Correcting login redirect #12932
Conversation
// The login menu item contains a redirection. | ||
// This will override the automatic change to the user preferred language | ||
// Retrieves the Itemid from a login form. | ||
$uri = new JUri($this->app->getUserState('users.login.form.return')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if no return URL is set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My test did not show any issue.
Do you prefer I first add a conditional?
if ($this->app->getUserState('users.login.form.return'))
{
$uri = new JUri($this->app->getUserState('users.login.form.return'));
[..]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I'm saying that I don't know what JUri will do if it gets a NULL value or an empty string or similar. NULL will most likely result in the current URL being used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand.
If JUri gets a null value, then $itemid is null and we switch to the next elseif when we do elseif ($itemid)
which is what we want here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mixed up the constructor with JUri::getInstance(). This one is ok.
if ($active->params['login_redirect_url']) | ||
{ | ||
// The login menu item form contains an internal URL redirection. | ||
// This will override the automatic change to the user preferred site language. | ||
$this->app->setUserState('users.login.form.return', JRoute::_($this->app->getUserState('users.login.form.return'), false)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are receiving the URL from the app, then send it through JRoute and set it again in the app. That feels pretty wrong... Looks like we'd have to do nothing here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the case exists and should be checked before checking for an itemid. This code is working. I am open to any suggestions to simplify this.
Would simply use
$this->app->setUserState('users.login.form.return', $this->app->getUserState('users.login.form.return'));
be OK, as we don't need JRoute anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, you are doing nothing in this place. You might as well write $something = $something;
That line is the equivalent of JRequest::setVar('test', JRequest::getVar('test')) If that should do anything, then this code is wrong. Otherwise this if-statement can simply be empty.
$this->app->setUserState('users.login.form.return', JRoute::_($this->app->getUserState('users.login.form.return'), false)); | ||
} | ||
elseif ($this->app->getUserState('users.login.form.return')) | ||
elseif ($itemid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use $uri->hasVar('Itemid') instead. That way you don't have to unnecessarily assign the variable above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That can be done indeed. Let's first agree on the above.
Thanks Hannes. Corrected. Now, when testing this, I found out an issue which is also present in 3.6.4 and was not taken care of. The problem comes from the fact that in both cases, we have the same $active menu item. Any idea how to solve that one? |
Ok. Tested on a monolanguage site and that issue is also present there... Will create an issue for that problem. |
See #12945 for the Read More issue. |
If not, should redirect to the menu item selected? What is the order of execution priorities here? This?
Also shouldn't exist a user default login and logout redirect parameters in com_users that would be the "use global" for both the menu item and the login modules? I'm saying this because we have other login form with |
First, one should consider the default preferred language for the user. It may be also be "default", i.e. the site default language. Login through the module: If it is and no redirection is set in the login module, then behavior is similar to a monolanguage site and login redirects to the same page. If it is not and no redirection is set in the login module, then it looks for an associated menu item in the user preferred language and login redirects to it. If there is no associated menu item in the site preferred language of the user and login is not done from the Home page, login redirects to the same page. If a redirection is set in the login module, then it tries to find an associated menu item in the site preferred language of the user and redirects to it. Login through a Login Menu Item If no redirection is set in the login menu item and it is not associated to a menu item tagged to the site preferred language of the user, the user will be redirected to the user Profile in the language where the login menu item is presented, whatever its preferred site language. If no redirection but there is an associated menu item tagged to the site preferred language of the user, the redirection will be to that menu item. If there is a redirection of type If the redirection set in the login menu item is an
That is totally unrelated to this PR and would be a new feature. |
I have tested this item ✅ successfully on ab0f2d4 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12932. |
I have tested this item ✅ successfully on ab0f2d4 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12932. |
RTC |
Pull Request for Issue #12920
When login in a multilingual site, the user should be redirected, if possible, to the associated menu item of the page containing the login module.
If redirections are set (in the login module as well as in a login menu item) they should use the possible associations for the redirect.
Summary of Changes
Using API to get the possible Itemid in order to redirect properly when
Automatic Change
is set to Yes in the language filter plugin.Added detailed comments explaining what each situation may obtain.
Testing Instructions
Create a multilingual site from a clean staging. Patch.
Add one more article per language and associate them.
Set the user login preferred site language to another language than the default site language.
Set the language filter plugin to use "Automatic Change"
NOTE: if the user preferred site language is not set, the default site language will be used. Testing does not change. Just replace in the instructions below
user preferred site language
bysite default language
.The following should work when testing, I added the code comments to clarify.
--------------
If login through a login menu item using the Internal URL redirection (on a multilingual site, that url should contain
&lang=xx-XX
):// The login menu item form contains an internal URL redirection.
// This will override the automatic change to the user preferred site language.
=> The user will be redirected to that Internal URL, whatever it is.
-------------
If login from a login menu item or a login module and a Menu Item redirection is set
// The login form contains a menu item redirection. Try to get associations from that menu item.
// If any association set to the user preferred site language, redirect to that page.
-------------
// The login form does not contain a Menu Item redirection.
// The active menu item has associations.
// We redirect to the user preferred site language associated page.
-------------
// We are on a Home page, we redirect to the user preferred site language Home page.
I.e. no need to associate the Home pages. They are automatically.
-------------
If Associations are not implemented, Automatic Change set to Yes, no redirection set to a Menu Item and login from another page than the Home page, the user should be redirected to the same page.
If login from a Home page, redirection will be set to the preferred site language Home page of the user.
-------------
If automatic change is set to No, behaviour will be the same as on a monolanguage site.
I.e. redirect to the same page or, if a redirection is set in the login module or login menu item, redirection to that url or menu item.
Documentation Changes Required
None. This broke with the new router because the code was not using the proper API.