Skip to content
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

Do not add default or active Itemid to every link without own menu item #19099

Merged
merged 4 commits into from
Jan 3, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Correctly redirect user to preferred site language association
  • Loading branch information
Tomasz Narloch committed Dec 20, 2017
commit fa6caa0abc72f1eca03d61414f1f4a58427251ae
55 changes: 31 additions & 24 deletions plugins/system/languagefilter/languagefilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,6 @@ public function onUserLogin($user, $options = array())
{
if ($this->params->get('automatic_change', 1))
{
$assoc = JLanguageAssociations::isEnabled();
$lang_code = $user['language'];

// If no language is specified for this user, we set it to the site default language
Expand All @@ -617,45 +616,53 @@ public function onUserLogin($user, $options = array())
$lang_code = $this->current_lang;
}

$foundAssociation = false;

$assoc = JLanguageAssociations::isEnabled();

// If association is enabled
if ($assoc)
{
// Retrieves the Itemid from a login form.
$uri = new JUri($this->app->getUserState('users.login.form.return'));

// Get Itemid from SEF or home page
$query = $this->app::getRouter()->parse($uri);

// Check, if the login form contains a menu item redirection.
if (!empty($query['Itemid']))
{
// Try to get associations from that menu item.
$associations = MenusHelper::getAssociations($query['Itemid']);

// If any association set to the user preferred site language, redirect to that page.
if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code]))
{
$associationItemid = $associations[$lang_code];
$this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $associationItemid);
$foundAssociation = true;
}
}
}

// Try to get association from the current active menu item
$active = $menu->getActive();

$foundAssociation = false;

/**
* Looking for associations.
* If the login menu item form contains an internal URL redirection,
* This will override the automatic change to the user preferred site language.
* In that case we use the redirect as defined in the menu item.
* Otherwise we redirect, when available, to the user preferred site language.
*/
if ($active && !$active->params['login_redirect_url'])
if (!$foundAssociation && $active && !$active->params['login_redirect_url'])
{
if ($assoc)
{
$associations = MenusHelper::getAssociations($active->id);
}

// Retrieves the Itemid from a login form.
$uri = new JUri($this->app->getUserState('users.login.form.return'));

if ($uri->getVar('Itemid'))
{
// 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.
if ($assoc)
{
$associations = MenusHelper::getAssociations($uri->getVar('Itemid'));
}

if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code]))
{
$associationItemid = $associations[$lang_code];
$this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $associationItemid);
$foundAssociation = true;
}
}
elseif (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code]))
if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code]))
{
/**
* The login form does not contain a menu item redirection.
Expand Down