I've ran into a situation where I needed to use a different content ID - for sections and categories - in the menu.
I will try to explain as possible as I can ... I've a multilingual website (sure!) and there's a press releases section. The contents on the press releases section. These are released in specific language according to the audience and will not be translated ... So I had :
1- Press releases in Arabic
2- Press releases in English
3- Press releases in French
I created 3 categories one for each language and created my default menu item to show a blog view and selected the default language ... then translated it to the 2 remaining language AND changed the category to display according to the corresponding language.
So, according to the joomfish, we should have 3 URLs :
- Code: Select all
1- website/index.php?option=com_content&view=blog&itemid=xx&id=category-id-1
2- website/index.php?option=com_content&view=blog&itemid=xx&id=category-id-2
3- website/index.php?option=com_content&view=blog&itemid=xx&id=category-id-3
The URLs change perfectly on the mod_mainmenu ... however; it doesn't follow this behavior on the mod_jflanguageselection !!!
From what I've experienced, I think that mod_jflanguageselection just check the URL variables and set the language code to the new language ... It doesn't go back to the database to check if the id has changed or not. The results was that my URLs was like this :
- Code: Select all
1- website/index.php?option=com_content&view=blog&itemid=xx&id=category-id-1
2- website/index.php?option=com_content&view=blog&itemid=xx&id=category-id-1
3- website/index.php?option=com_content&view=blog&itemid=xx&id=category-id-1
Note, mod_mainmenu is getting back the correct URL with the correct language. The problem here is with the URL that mod_jflanguageselection returns.
To solve this issue, I've modified the _createHRef function within helper.php as follow :
Please note this is applied to mod_jflanguages coming with Joom!fish version 2.2!
1- Get the original id from column "link" in #__menu table using the itemId.
note : I had to set $db->_skipSetRefTables = true otherwise if I get data from reference table if I switched the language
at line 124 , right after
- Code: Select all
$hrefVars = '';
Add the following :
- Code: Select all
// Selecting the original id from the database by the item id
// Checking reference table is skipped
$query = 'SELECT * ' .
' FROM #__menu ' .
' WHERE id = '. $vars['Itemid'];
$db->_skipSetRefTables = true;
$db->setQuery($query);
$rows = $db->loadObjectList();
$originalId = explode("&id=",$rows[0]->link);
$originalId = $originalId[1];
2- Check to see if the itemid being called has any reference in the translation table.
- Code: Select all
// Checking if the current itemid is translated and present in the reference table
$query = 'SELECT * ' .
' FROM #__jf_content ' .
' WHERE reference_table="menu"'.
' AND reference_id = '. $vars['Itemid'];
$db->setQuery($query);
$db->_skipSetRefTables = false;
$rows = $db->loadObjectList();
$theId = explode("&id=",$rows[1]->value);
$theId = $theId[1];
3- Selecting the language shortcode from the #__languages table
- Code: Select all
//Selecting the language shortcode of the translated content
$query = 'SELECT sef ' .
' FROM #__languages ' .
' WHERE lang_id = '. $rows[1]->language_id;
$db->setQuery($query);
$rows = $db->loadObjectList();
$otherLang = $rows[0]->sef;
4- Right after the setting of the lang variable to the correct value, I added a check to see If the id from the reference table is not set to null and the language the module is echoing now is the same language for that content with the reference id. It will set the id to the correct value, if not it will revert to the original value . All this wrapped with a check if we are dealing with com_content only
Right after
- Code: Select all
$vars['lang']=$code;
- Code: Select all
// if we are working with com_content
if($vars['option'] == "com_content"){
// Checking if there's an ID for the translated content and the module is currently echoing the translated language
// We set the ID of the content to the one we got from the reference table
if($theId != null && $vars['lang']== $otherLang ){
$vars['id']=$theId;
} else {
// If the case is not true, we set the ID to the origional content ID
// This is to prevent the problem of overwrting the original ID when an ID with a translation is active
$vars['id']=$originalId;
}
}
I am not the best coder, I know there's a huge room for improvement... Please feel free to check, try and if you think it can be better or have any notices please don't hesitate to share it.
Thanks a lot.
