Adapting a Joomla 1.5 extension to Joomla 2.5

From Joomla! Documentation

Revision as of 08:29, 25 January 2011 by Mariusvr (Talk | contribs)

Quill icon.png
Content is Incomplete

This article or section is incomplete, which means it may be lacking information. You are welcome to assist in its completion by editing it as well. If this article or section has not been edited in several days, please consider helping complete the content.
This article was last edited by Mariusvr (talk| contribs) 5 years ago. (Purge)

This article is written to help developers upgrade their extensions from Joomla 1.5 to Joomla 1.6. If you have any further tips, feel free to add them onto this wiki article.

System setup

This document assumes that you are running the program eclipse for your development. This will allow you to automate most of the Joomla conversion process. For more instructions on how to setup eclipse, see Setting up your workstation for Joomla! development.

Background reading

What's new in Joomla 1.6#Developers describes most changes of Joomla 1.6 and how this affect developers.

Updating your Joomla 1.5 language files to work on Joomla 1.6

Using the native php ini parser for language files has many benefits including much faster performace. Converting your exisiting Joomla 1.5 into the new format is very easy if you use a coding platform like eclipse. Search your file for *.ini in your project of choice. Then use the following search/replace values to automatically, replace exisiting quotes, add quotes to string values and update your comments.

An earlier version of this document noted that double quotes were not allowed, but see the PHP parse_ini_file documentation and below for further information.

  1. Single quotes are now not allowed. This can be easily bypassed by searching ' and replace with ".
  2. Put a closing double quote at end of line if not empty or a comment. Find ^((?!#).+)\R replace with $1"\R
  3. Put an opening quote at start of translated string if not empty or comment. Find ^((?!#).+?\=)(.+)\R replace with $1"$2\R
  4. Now replace the hash comments with the new semi colon. Find ^# and replace with ;
  5. Remove any illegal strings that can prevent files loading. Find ^(null|yes|no|true|false|on|off|none)=(.+)\R and replace with nothing.

If you do not remove these illegal strings, then your language file won't load and you won't get any error message. The now "illegal" strings in the language file like NO, are now handled by adding a 'J' in-front of them. Just make sure you change these language strings in your XML files as well. You can include in your language file:

;forbidden words

Changing Javascript function overrides

Joomla now has some of its Javascript functions prefixed with "Joomla". This means the functions are always unique and won't clash with other javascript functions on your server/webpage. However, you now need a different method to override the default Joomla Javascript. The Joomla 1.5 method was:

function submitbutton(pressbutton) {
var form = document.adminForm;
    if (pressbutton == 'applyconfig') {
        //do something unique
        form.action.value = 'apply'

For Joomla 1.6 you need to copy your exisiting function but modify your top line to:

Joomla.submitbutton = function(pressbutton) {
var form = document.adminForm;
    if (pressbutton == 'applyconfig') {
        //do something unique
        form.action.value = 'apply'

Changing removed functions

Some functions were removed for various reasons. You can find a list of them on What's new in Joomla_1.6#Removed_features.

Note that the ADODB compatibility methods included function like $db->Execute($query) which now need a separate $db->setQuery($query);$db->Query();

Renamed events

A large number of the Joomla 1.5 events have been renamed. Here is the list of renamed events.

  • onContentAfterSave
  • onContentAfterTitle
  • onContentAfterDisplay
  • onContentBeforeDisplay
  • onContentBeforeSave
  • onContentSearch
  • onContentSearchAreas
  • onUserAuthenticate
  • onUserAfterDelete
  • onUserAfterSave
  • onUserBeforeDelete
  • onUserBeforeSave
  • onUserLogin
  • onUserLogout
  • All content events (except for search and search areas) now pass a 'context' as the first argument to alert the plugin as to what type of content is being passed. The plugin event may or may not heed this context.

This means that if you use Joomla events you have two options:
1) rename the event and your extension can only be used on Joomla 1.6
2) create your own "legacy layer" and add the new event function name to your plugin. Here is an example of the user plugin:

    //joomla 1.6 compatibility code 
 	public function onUserLogin($user, $options){
 	    $result = $this->onLoginUser($user, $options);
 	    return $result;
	public function onUserLogout($user)	{
 	    $result = $this->onLogoutUser($user);
 	    return $result;
	public function onUserAfterDelete($user, $succes, $msg)	{
 	    $result = $this->onAfterDeleteUser($user, $succes, $msg);
 	    return $result;
	public function onUserBeforeSave($user, $isnew, $new){
 	    $result = $this->onBeforeStoreUser($user, $isnew, $new);
 	    return $result;	
	public function onUserAfterSave($user, $isnew, $success, $msg){
 	    $result = $this->onAfterStoreUser($user, $isnew, $success, $msg);
 	    return $result;			

Changing name="adminForm" to id="adminForm"

To create your own admin forms in joomla you now need to use id="adminForm". This is because the use of the tag "name" is not valid HTML strict and has compatibility issues when used in XHTML served as XML.\. Although there is build in compatibility check to look for the old name="adminForm" tag, it is best to add the new id tag. Depending on the features you want to use you may need to include both, name="adminForm" and id="adminForm" because not all core functionality has been updated to use id's. An example of the new form code is:

<form method="post" action="index.php" name="adminForm" id="adminForm"></form>

Removing references to index2.php and index3.php

Joomla 1.0 had different index files to serve admin content in different manners. Joomla 1.6 has now got better way to handle this and you need to search your codebase for "index2.php" and "index3.php" to ensure you don't have any Joomla 1.0 style links. If you need to display your component without any of the other Joomla 1.6 admin content (menus, etc) then add the following to the url: "&tmpl=component"

Upgrading core table and field name usage

Many of the core Joomla tables have been simplified, combined or renamed. This was needed to get rid of some limitation dating back to Joomla 1.0. This means however that if you have code that directly manipulates Joomla tables, that you need to add a function that detects Joomla 1.6 and had different SQL queries based on the joomla version. Plase note that both tables and field names have been renamed or removed. An example is the following function that can find if a plugin is published on both Joomla 1.5 and 1.6:

function getPluginStatus($element, $folder) {
    //get joomla specs
    $db = & JFactory::getDBO();		
    $version = new JVersion;
    $joomla = $version->getShortVersion();
    if(substr($joomla,0,3) == '1.6'){
        //Joomla 1.6 code
        $query = 'SELECT published FROM #__extensions WHERE element=' . $db->Quote($element) . ' AND folder=' . $db->Quote($folder);
    } else {
        //Joomla 1.0/1.5 code
        $query = 'SELECT published FROM #__plugins WHERE element=' . $db->Quote($element) . ' AND folder=' .   $db->Quote($folder); 
    $result = $db->loadResult();
    return $result;

Changing in the XML installer manifest file

Joomla 1.6 now uses a more streamlined approach to the XML file inside the ZIP file that installs Joomla extentions.

New mootools version

Most important is that the Ajax class has been depreciated and replaced by the Request class. That means that if you use ajax calls you need to have a version switcher (below a sample code)

$version = new JVersion;
$joomla = $version->getShortVersion();
..... (your code) ....
    /* our ajax istance for starting the sync */
    <?php  if(substr($joomla,0,3) == '1.6'){
 echo 'var ajax = new Request.HTML({
           url: url,';
    } else {
 echo 'var ajax = new Ajax(url, {';
.... your code .....
    <?php  if(substr($joomla,0,3) == '1.6'){
     echo 'var ajaxsync = new Request.HTML({
        url: url, ';
    } else {
echo 'var ajaxsync = new Ajax(url, {';
.... your code .....

Also another common usuage of mootools in Joomla is the popup box. The Joomla 1.5 javascript code to close this box is:


in Joomla 1.6 you need to use:


Converting your JParameters to JForms

Joomla 1.6 now uses the JForms class to handle parameters and it has also changed the way parameters are defined in your XML files. To make menu/component/module/plugin parameters work, first you need to update the XML file. Here is an automated way to handle the bulk of the conversion. (added "" to the examples below so you can see spaces in the search query as well). Use eclipse to search and replace parameters in *.xml files

replace "<param " with "<field "
replace "</param>" with </field>"
replace "<params> with "<config><fields name="params"><fieldset name="basic">"
replace "<params*?> with "<config><fields name="params"><fieldset name="basic">"
replace "</params>" with "</fieldset></fields></config>"
replace "<install " with "<extension "
replace "</install>" with "</extension>"

Change the "extension" node to add the following attributes:

  • Keep the existing "type" attribute
  • version="1.6.0"
  • client="site"
  • method="upgrade"

Example for a module:

<extension type="module" version="1.6.0" client="site" method="upgrade">

Now if you want to use your joomla extension on both Joomla 1.5 and 1.6 you will need to go to your "team synchronising" view in eclipse. Double click on your changed xml file, which will open the compare editor. Then simply copy-paste back your old Joomla 1.5 params into your new Joomla 1.6 xml file and save.

If you have custom parameter types, you will need to do some additional work. In Joomla 1.5 you would use the following code:

<params addpath="/administrator/components/com_yourname/elements">

In joomla 1.6 JParameter classes won't work and you will need to convert your jparameter fields into JForm fields. Create a new directory and copy your "old elements" into them. Then you need to load these new fields with the individual parameter

<field name="sample" type="sampleField" size="5" default=""			label="sampleField" description="sampleField" addfieldpath="/administrator/components/com_yourname/fields"/>

Use eclipse to search and replace files in your newly created fields directory. replace "JElement" with "JFormField"
replace "var $_name =" with "public $type ="
replace "function fetchElement($name, $value, &$node, $control_name)" with "protected function getInput()"

Then you still need to replace the references to $control_name and others in your new JForm field, but at least the bulk of the work has been done automatically

renamed core component names and login form parameters

A login module for Joomla 1.5 will not work without modifications on Joomla 1.6. Here is a part of the logout module that will work on both Joomla 1.5 and Joomla 1.6. You can compare the two to see the difference in input names.

        $version = new JVersion;
        $joomla = $version->getShortVersion();
        if(substr($joomla,0,3) == '1.6'){
            //joomla 1.6 format          
            $output .= '<input type="hidden" name="task" value="user.logout" />';
            $output .= '<input type="hidden" name="option" value="com_users" />';
        } else {    
            //joomla 1.5 format
            $output .= '<input type="hidden" name="task" value="logout" />';
            $output .= '<input type="hidden" name="option" value="com_user" />';            

here is the code for the login module

        $version = new JVersion;
        $joomla = $version->getShortVersion();
        if(substr($joomla,0,3) == '1.6'){        
            //joomla 1.6 format     
            $output .= '<input type="hidden" name="task" value="user.login" />';
            $output .= '<input type="hidden" name="option" value="com_users" />';
            $output .= '<input id="modlgn_passwd" type="password" name="password" class="inputbox" size="18" alt="password" /> ';
        } else {
            //joomla 1.5 format
            $output .= '<input type="hidden" name="task" value="login" />';
            $output .= '<input type="hidden" name="option" value="com_user" />';     
            $output .= '<input id="modlgn_passwd" type="password" name="passwd" class="inputbox" size="18" alt="password" /> ';               	

These changes might also apply to front-end forms of other Joomla core components (more information needed)

ACL changes

Joomla 1.6 now has an advanced ACL system. It is unknown how this affects people that have previously used the ACL API in their extension. Please add some information here if you know more.

Plugin files now in different locations

Joomla 1.6 now creates a different hierarchy structure for plugins. Files are no longer placed where they used to be, so if your other parts of your application (comp, mods, etc.) expects them to be in a certain position, it won't work. The change has been that now plugins are in an additional subdirectory. If you only load your plugins via the 1.5 API you should be fine.

  • Joomla 1.5 example location
JPATH_SITE . DS . 'plugins' . DS . 'authentication' . DS . 'example'. DS . 'example.php';
  • Joomla 1.6 example location
JPATH_SITE . DS . 'plugins' . DS . 'authentication' . DS . 'example.php';

Component conversion planning items

Here is an informal and unordered list of things to consider if you are planning to convert your 1.5 extensions to 1.6. They are mostly from the Google general development group around the time of 1.6b15.

1. Language file - J!1.6 enforces strict rules for language translations. No more spaces in the keys or values that aren't enclosed in double quotes. This change will hopefully get much better performance than the previous loose enforcement.

2. Changes to view parameters - J!1.6 has a strict new way of specifying parameters for views. J!1.5 allowed a bit of freedom where the parameters could be defined at the view.html.php level but now it has to be at the tmpl level. AE believes the view paramters were removed.

4. Installation process - preflight, postflight, etc - These are new events that can screw up an existing installlation process. -1 on me for not documenting the process while stepping through xdebug. They should be totally optional access points to the installation process. But if your 1.5 install process is tricky for some reason, then these can be used to do clean up activities.

5. Custom fields - This could be a could be huge depending the volume and vagaries your 1.5 usage of custom fields. The entire process changed and now the custom fields must inherit from J! base classes. (AE) This is no different from 1.5 inheriting from JElement. In 1.6 you inherit from JFormField which is a much more robust class.

6. Admin template changes - Admin functions that depended on certain functions, naming conventions etc no longer work. Khepri has been removed. Other admin functions/libraries may have changed.

7. ACL - gid and aid have been removed. Significant changes to ACL archtecture. Bricking refers to totally locking your self and everyone else out - Last chance backdoor involves adding a emergency pw to the config file.

8. Renamed methods, table names, etc.

9. sys.ini language translation file - This file is used for installation process translations...

10. include folder - All of the libraries (Archive, domit, js, PEAR, etc) in the include folder have been removed in J!1.6.

11. Mootools version changed from 1.1 (Joomla 1.5.19 has a upgrade plug-in for 1.2) to 1.3. Mootools 1.3 is not compatible with Mootools 1.1 but it is compatible with Mootools 1.2.

12. Use paths defined in defines.php. (Note they are different for the site and the administration)