luya-module-cms icon indicating copy to clipboard operation
luya-module-cms copied to clipboard

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

Open Antikon opened this issue 6 years ago • 5 comments

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

Antikon avatar Aug 29 '19 14:08 Antikon

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?

nadar avatar Aug 29 '19 15:08 nadar

Sure, but a little bit later

Antikon avatar Aug 29 '19 16:08 Antikon

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:

https://github.com/luyadev/luya-module-cms/blob/8639b26d336e9536fb77c36de197527eb91b615c/src/widgets/LangSwitcher.php#L199-L208

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

nadar avatar Aug 30 '19 08:08 nadar

I've made some investigations. The LangSwitcher widget itself can add additional params to URL (see line 229). https://github.com/luyadev/luya-module-cms/blob/9ce31a834c05d7b14cb2e54f4b8f0bb544ad70aa/src/widgets/LangSwitcher.php#L214-L231

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.

Antikon avatar Sep 01 '19 13:09 Antikon

  • 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?

nadar avatar Oct 01 '19 15:10 nadar