My hack to the mod_jflanguageselection helper class

Technical talks related to the Joom!Fish project. All those discussions are mostly related to development or high-profile usage of the extension.

My hack to the mod_jflanguageselection helper class

Postby ahmadalfy on Wed Dec 21, 2011 2:24 pm

Greetings all!

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;
add

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.
ahmadalfy
Newbee
 
Posts: 14
Joined: Tue Dec 01, 2009 1:39 am

Re: My hack to the mod_jflanguageselection helper class

Postby ahmadalfy on Wed Dec 21, 2011 2:26 pm

I would have posted the modified file, but that version is only for the club members. Regards
ahmadalfy
Newbee
 
Posts: 14
Joined: Tue Dec 01, 2009 1:39 am

Re: My hack to the mod_jflanguageselection helper class

Postby alex on Wed Jan 25, 2012 11:15 pm

Hi,

This looks like an interesting version. Would you mind to create a pull request for us on github? This way we can also recognize your work with adding it to our codebase.

The correct repository is:
https://github.com/JoomFish/jf-core

It is likely that we will release an additional version at some point in time but also we can integrate the changes into the https://github.com/JoomFish/jf-future branch that reflects the 2.5 compatible version.

Last but not least, our development code is always free accessible on github. So feel free to post direct file patches here at any time. Just because something is available in our club as a package does not mean we hide it from the public. I just like to encourage you to let you not stop with your motivation just because of a club download.

Best regards and many thank's

Alex
JoomFish core team member
Think Network GmbH - strategic consulting and internet services

You need more Joomla Support? May be Open Source Support Desk can help you!
User avatar
alex
Core Member
 
Posts: 1920
Joined: Fri Oct 19, 2007 4:58 pm
Location: Konstanz, Germany

Re: My hack to the mod_jflanguageselection helper class

Postby ahmadalfy on Wed Feb 15, 2012 9:40 am

Thanks a lot Alex for your encouragement. I just read your update now.
I discovered a bug on my code I am working on it. Will create the pull over gitfhub asap.

Thanks for the clarification about posting the files

Best Regarsd
ahmadalfy
Newbee
 
Posts: 14
Joined: Tue Dec 01, 2009 1:39 am


Return to Joom!Fish Tech-Talk

Who is online

Users browsing this forum: No registered users and 0 guests