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

LangSwitcher should keep query string in URL (or at least have a such option) #220

Open
Antikon opened this issue Aug 29, 2019 · 5 comments
Assignees
Labels

Comments

@Antikon
Copy link
Contributor

Antikon commented Aug 29, 2019

One of the typical scenarios on page is to update some model. In this case an URL looks like http://host/lang/module/controller/update?id=5.

Switching the language should keep the same form but change the labels and so on.

At present the widget drops a query string, so the URL becomes http://host/lang2/module/controller/update. It causes Bad Request since the id is missed.

LUYA Core Version: 1.0.20
LUYA CMS Version: 2.1.0

@nadar
Copy link
Member

nadar commented Aug 29, 2019

yes indeed. adding query params should and must be possible. for quick fix: add an url rule, better for seo anyhow :-)

would you like to send a PR?

@Antikon
Copy link
Contributor Author

Antikon commented Aug 29, 2019

Sure, but a little bit later

@nadar nadar added the bug label Aug 30, 2019
@nadar
Copy link
Member

nadar commented Aug 30, 2019

Would be nice. otherwise i will pick the issue but not within next few days. If you need assistance, let me know. The check for exisiting params should be done here i assume:

private function ensureHostInfo($link, array $lang)
{
// check if host info mapping is available.
$domain = Yii::$app->composition->resolveHostInfo($lang['short_code']);
// no domain is defined for this host info, therfore just prepend the current host:
if (!$domain) {
$domain = Yii::$app->urlManager->hostInfo;
}
return Url::ensureHttp($domain) . '/' . ltrim($link, '/');

But we have to compare the get parameters against the current url - as get params will also be resolved when using url rules

@Antikon
Copy link
Contributor Author

Antikon commented Sep 1, 2019

I've made some investigations. The LangSwitcher widget itself can add additional params to URL (see line 229).

public function run()
{
$currentLang = Yii::$app->composition['langShortCode'];
$rule = Yii::$app->menu->currentUrlRule;
$items = [];
foreach (self::getDataArray() as $langData) {
$item = $langData['item'];
$lang = $langData['lang'];
if ($item) {
if ($item->type == NavItem::TYPE_MODULE && !empty($rule)) {
$routeParams = [$rule['route']];
foreach ($rule['params'] as $key => $value) {
$routeParams[$key] = $value;
}

The URL rule in my case comes from ModuleReflection class
https://github.com/luyadev/luya/blob/0860ac787cc5e37aa966446952e0f524ff3d3edd/core/base/ModuleReflection.php#L133-L180

My question is what is 'args' and 'originalArgs' and how they should be populated from parseRequest method (line 156)?

If we use $route = $this->request->resolve() instead, then the 'path' parameter from CatchAllUrlRule will be added also.

@nadar
Copy link
Member

nadar commented Oct 1, 2019

  • args: This will contain all params from GET request or if defined in url rules, only the ones from the url rules.
  • originalArgs: This will only contain the arguments parsed trough url manager.

Does that help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants