-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[4.0] Multilingual : Correcting info-block category and parent category urls #21916
Conversation
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.
We need these changs for the other core components, too.
$item->catslug = $item->category_alias ? ($item->catid . ':' . $item->category_alias) : $item->catid; | ||
$item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id; | ||
$item->catlanguage = $item->category_language; | ||
$item->parentlanguage = $item->parent_language; |
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.
Why are you adding these attributes again here? We don't need to duplicate these attributes.
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.
We also don't need the slugs for the categories. For the categories we only need the ID.
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.
Why are you adding these attributes again here? We don't need to duplicate these attributes.
Looks like they are needed for the info-block JLayout
We also don't need the slugs for the categories. For the categories we only need the ID.
I was adapting to the info-block layout which uses slugs.
|
||
// No link for ROOT category | ||
if ($item->parent_alias === 'root') | ||
{ | ||
$item->parent_slug = null; | ||
$item->parent_slug = null; |
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.
Can you revert this change here? Don't want to have unnecessary changes...
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.
sure
$item->catslug = $item->category_alias ? ($item->catid . ':' . $item->category_alias) : $item->catid; | ||
$item->catlanguage = $item->category_language; | ||
$item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id; | ||
$item->parentlanguage = $item->parent_language; |
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, don't duplicate the attributes and we don't need the slugs.
$item->catslug = $item->category_alias ? ($item->catid . ':' . $item->category_alias) : $item->catid; | ||
$item->catlanguage = $item->category_language; | ||
$item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id; | ||
$item->parentlanguage = $item->parent_language; |
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, don't duplicate the attributes and we don't need the slug.
$item->catslug = $item->category_alias ? ($item->catid . ':' . $item->category_alias) : $item->catid; | ||
$item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id; | ||
$item->catlanguage = $item->category_language; | ||
$item->parentlanguage = $item->parent_language; |
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.
See comment above...
{ | ||
$lang = Factory::getLanguage()->getTag(); | ||
$link .= '&lang=' . $lang; | ||
} |
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 $lang changes should not be necessary. It defaults to the current language if no language is given. Did you check if this is necessary? The $layout is indeed wrong here. In any case, you should change the fingerprint of these methods to not have the $language (and also the $catid) be optional anymore. These are always required.
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 $lang changes should not be necessary. It defaults to the current language if no language is given. Did you check if this is necessary?
Alas it is. Tested that. Specially for the info-block at least.
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.
In any case, you should change the fingerprint of these methods to not have the $language (and also the $catid) be optional anymore. These are always required.
Any hint how to do that? And would it be B/C ?
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.
Simply remove the optional parameter stuff here. So from
public static function getCategoryRoute($catid, $language = 0)
to
public static function getCategoryRoute($catid, $language)
This is not B/C, but we are talking about Joomla 4.0 here, where we can break B/C and this is a case where we have to break it, to clear up this longlasting bug.
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.
Also, please remove the $lang changes. We should never have to add something if the language is *. If this currently is necessary, we have to fix this in another place, but not here. Not only because it is wrong, but also because this method is just an amenity, not a necessity. These methods only concatenate a string, nothing more, they don't look up anything. People can also just hand in their own handcrafted URL into the router, which could not contain the language parameter. So we have to see what the issue is here in the router and fix that and not hand in fake parameters. This code has to go.
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.
Also, please remove the $lang changes.
My problem here is that if I remove it, full tests can't be done on this PR as soon as we have a category set to ALL languages.
This is not B/C, but we are talking about Joomla 4.0 here, where we can break B/C and this is a case where we have to break it, to clear up this longlasting bug.
I would also do for getArticleRoute()
I guess
I am not opposed to it. Need OK from
@wilsonge @mbabker
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 have a solution for the $lang stuff. Will add later on.
On it for most parts except the fingerprint of the method |
@Hackwar After merge, will work on other components. |
2ef6a95
to
c21eb52
Compare
@Hackwar |
if ($language !== '*') | ||
{ | ||
$link .= '&lang=' . $language; | ||
} |
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.
Can you undo changes that do not do anything in this file, I mean just delete the part with the layout.
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.
will do
after some further tests, i think my changes in menurules are not enough. |
// Set the language to the current one when multilang is enabled and item is tagged to ALL | ||
if (Multilanguage::isEnabled() && $language === '*') | ||
{ | ||
$language = Factory::getLanguage()->getTag(); |
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.
This should work too $language = $this->router->app->get('language');
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.
It does indeed. More in the style of that file than the present code. Changing now. :)
restarted drone as non-related error |
The code is OK. I wonder if this issue occurs on J3? |
I have tested this item ✅ successfully on e06a014 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/21916. |
1 similar comment
I have tested this item ✅ successfully on e06a014 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/21916. |
Thanks |
…ry urls (joomla#21916) * [4.0] Correcting info-block category and parent category urls * Getting rid of category slugs thanks Hannes * missing one cat language variable * Correcting routing for archived * Getting the active language when item is tagged to ALL * Load current language when item is set to ALL * factory not used * better code for menurules thanks @csthomas
Problem: on a multilingual site, when displaying the info-block for articles in frontend , the urls of the category and parent category are real bad.
Summary of Changes
ContentHelperRoute::getCategoryRoute()
should ALWAYS contain the$language
variable.This PR adds it wherever necessary, including in
layouts/joomla/content/info-block/
corresponding files. Queries are modified to also select the category language. The language is also added in data.com_content/helpers/route.php
should cope with categories set to ALL languagesThe code is modified to take this into account as, in this case, the language to use in the url should be the language of the UI content language.
com_content/helpers/route.php
should not add for example&layout=cassiopeamyblog
to the end of the sef url when such a specifichtml/com_content/category/myblog.etc
menu item type is present in the template.To solve this, I had to revert [com_content][Multilanguage] - fix link when layout and association #19681
Testing Instructions
Install a multilingual site with 2 content languages.
Tests can be done on a single language. Choose en-GB for example as it is easier.
Create some categories and articles in these categories both tagged to the same language [CATen-GB, CATfr-FR].
Create a home blog menu item for each content language to display one CATen-GB and one CATfr-FR
Make sure you create a (hidden or not)
List All Categories
menu item tagged to en-GB in mainmenu en-GB.=> This is important as any category which has no specific menu item will still get a nice sef url.
Create also a Category set to ALL language and a child category of that category (tagged to ALL or to en-GB). Add to the child category an article tagged to en-GB ("Articletest").
Create a single menu item in mainmenu en-GB to display the "articletest" article.
Now, the second part of the test concerns the revert of the layout code in route.php.
To test this, it is necessary to add a new menu item type.
Find here a .zip of the files to add in
/templates/cassiopeia/html/com_content/category/
myblog.zip
Create a menu item using this type in mainmenu en-GB to display any category not yet displayed by the former menu items.
In Articles Options, make sure show category and link as well as show Parent category and link are set to yes.
Make sure all your menu items use these global settings
Expected result
When clicking on the Category or Parent category links you should get nice urls
not containing some stuff like
?view=category&id=18
or
&layout=cassiopeamyblog
when using the custom menu item typeInstead one may get for example when no menu item for the category
/en/allcategories-en-gb/category-all
(here set to ALL)or
/en/allcategories-en-gb/category-all/othercaten-gb
(category set to en-GB)and same for the custom menu item type (myblog menu item type)
Note A
Reverting #19681 is necessary.
We should look for another way to implement this feature.
Note B
The modifications concerning getCategoryRoute() and route.php should also be done for other components using this method.
@alikon @Hackwar @csthomas