In the course of updating our extensions to Joomla 1.6 we have managed to figure out some useful information about the differences between Joomla 1.5 and 1.6. There have been some big changes in the format of the installation package, which this article explores.

Format of the Installation Manifest

There have been some changes to the format of the installation manifest xml file. The root <install> tag has been replaced with an <extension> tag, while the <params> and <param> tags have been replaced with the <fields> and <field> tag respectively. The <fields> tags are now placed in a <config> tag container. The rest of the layout remains much the same. So a typical layout for a module in Joomla 1.6 would be:

<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="1.6.0" method="upgrade" client="site">
<name>My Module</name>
<author>Jo Bloggs</author>
<creationDate>July 2010</creationDate>
<copyright>Inspiration Web Design</copyright>
<license>GPL</license>
<authorEmail>

me@myaddress.comThis e-mail address is being protected from spambots. You need JavaScript enabled to view it

</authorEmail>
<authorUrl>www.mysite.com</authorUrl>
<version>1.0.0</version>
<description>Mails a link to the current page</description>
<files>
  <filename module="my_module">my_module.php</filename>
  <filename>helper.php</filename>
  <filename>index.html</filename>
  <filename>tmpl/default.php</filename>
  <filename>tmpl/index.html</filename>
  <folder>assets</folder>
</files>
<config>
  <fields name="params">
    <fieldset name="basic" label="Module Parameters" description="Configure Module">
    <field name="fromEmail" type="text" default="" label="from email address"  />
    <field name="bcc" type="text" default="" label="bcc" description="DESCBCC" />
    <field name="filterEmails" type="textarea" cols="20" rows="3" label="invalid emails"  />
    <field name="moduleclass_sfx" type="text" default="" label="Module Class Suffix"  />
    <field name="use_slider" type="list" default="0" label="Use mootools slider" >
      <option value="1">Yes</option>
      <option value="0">No</option>
    </field>
    <field name="use_cookie" type="list" default="1" label="Remember slide state" >
      <option value="1">Yes</option>
      <option value="0">No</option>
    </field>
    <field name="use_detection" type="list" default="0" label="Use Extended URL detection">
      <option value="1">Yes</option>
      <option value="0">No</option>
    </field>
    </fieldset>
  </fields>
</config>
<languages>
  <language tag="en-GB">en-GB.my_module.ini</language>
  <language tag="en-US">en-US.my_module.ini</language>
</languages>
</extension>


Adding Custom Parameters

So how do you go about adding custom parameters? If you are familiar with doing this with Joomla 1.5 you will remember that this involved extending the JElement Class, and overriding the fetchElement() method. This method was used to generate the html for the required field.

In Joomla 1.6 the process is quite similar, in this case we need to extend the JFormField Class. This Joomla class includes a getInput() method, which we can override to generate the html for the form field. The main difference from Joomla 1.5 is in how we access the name, value and other attributes of the form field. In Joomla 1.5 these were passed as parameters to the fetchElement() method. In Joomla 1.6 these are pre-populated as properties of the JFormField object that we are working with. So, for example to access the name of the form field we simply refer to it by $this->name. The class include a variable $type which must be set to the name of the field type.

In case this is not all crystal clear, the best way to illustrate this is with a example. The example below generates a list of currently published Joomla articles arranged by category.

<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );


jimport('joomla.html.html');
jimport('joomla.form.formfield');//import the necessary class definition for formfield


/**
 * Supports an HTML select list of articles
 * @since  1.6
 */
class JFormFieldArticles extends JformField

{
      /**
  * The form field type.
  *
  * @var  string
  * @since  1.6
  */
      protected $type = 'Articles'; //the form field type

      /**
  * Method to get content articles
  *
  * @return array The field option objects.
  * @since  1.6
  */
      protected function getInput()
      {
  // Initialize variables.
  $session = JFactory::getSession();
  $options = array();
 
  $attr = '';

  // Initialize some field attributes.
  $attr .= $this->element['class'] ? ' class="'.(string) $this->element['class'].'"' : '';

  // To avoid user's confusion, readonly="true" should imply disabled="true".
  if ( (string) $this->element['readonly'] == 'true' || (string) $this->element['disabled'] == 'true') {
   $attr .= ' disabled="disabled"';
  }

  $attr .= $this->element['size'] ? ' size="'.(int) $this->element['size'].'"' : '';
  $attr .= $this->multiple ? ' multiple="multiple"' : '';

  // Initialize JavaScript field attributes.
  $attr .= $this->element['onchange'] ? ' onchange="'.(string) $this->element['onchange'].'"' : '';


    //now get to the business of finding the articles
     

  $db = &JFactory::getDBO();
  $query = 'SELECT * FROM #__categories WHERE published=1 ORDER BY parent_id';
  $db->setQuery( $query );
  $categories = $db->loadObjectList();
 
  $articles=array();
 

  // set up first element of the array as all articles
  $articles[0]->id = '';
  $articles[0]->title = JText::_("ALLARTICLES");
 

    //loop through categories
    foreach ($categories as $category) {
     $optgroup = JHTML::_('select.optgroup',$category->title,'id','title');
     $query = 'SELECT id,title FROM #__content WHERE catid='.$category->id;
     $db->setQuery( $query );
     $results = $db->loadObjectList();
     if(count($results)>0)
     {
    array_push($articles,$optgroup);
    foreach ($results as $result) {
     array_push($articles,$result);
    }
     }
    }  
  
  // Output
 
  return JHTML::_('select.genericlist',  $articles, $this->name, trim($attr), 'id', 'title', $this->value );
 
      }
}


Simples!

Note that there are other ways of tackling this. Among the predefined field types that Joomla 1.6 supplies is the 'list' type, which defines the JFormFieldList class, which in turn is an extension of JFormField. We could have chosen to extend The JFormFieldList instead. This class returns a generic select list field. It includes a method, getOptions(), which returns the options available. We could have chosen to over-ride this method to return the articles as a list of options.

Adding the Custom Form Field to The Installation Package


The custom form field is added to your installation package using an addfieldpath attribute added to the < fields> tag. In the example below we assume that the articles field definition is placed in a file called articles.php which is placed in a folder /modules/mod_mymodule/fields (note that this is relative to the root folder of your site).

<fields name="params" addfieldpath="/modules/mod_mymodule/fields">

Backwards Compatibility With Joomla 1.5

In fact we have found that the Joomla 1.6 installer will understand the old <install> tag, so it is possible to create an installation package that will install in Joomla 1.6 and Joomla 1.6. To do this, use the <install> tag:-

<install type="module" version="1.5.0" method="upgrade" client="site">

The parameters for Joomla 1.6 can be added in a <config> tag, while the old <params> tag can be used for the Joomla 1.5 parameters. The installers will simply ignore the tags that they do not use.

If you want to add custom parameters for versions 1.5 and 1.6 we have found that the easiest way to do this is to have separate folders for the separate definitions of the custom fields, for example called 'elements' and 'fields' respectively.

Reasons why you must trust ASPHostPortal.com

Every provider will tell you how they treat their support, uptime, expertise, guarantees, etc., are. Take a close look. What they’re really offering you is nothing close to what ASPHostPortal does. You will be treated with respect and provided the courtesy and service you would expect from a world-class web hosting business.

You’ll have highly trained, skilled professional technical support people ready, willing, and wanting to help you 24 hours a day. Your web hosting account servers are monitored from three monitoring points, with two alert points, every minute, 24 hours a day, 7 days a week, 365 days a year. The followings are the list of other added- benefits you can find when hosting with us:

- DELL Hardware
Dell hardware is engineered to keep critical enterprise applications running around the clock with clustered solutions fully tested and certified by Dell and other leading operating system and application providers.
- Recovery Systems
Recovery becomes easy and seamless with our fully managed backup services. We monitor your server to ensure your data is properly backed up and recoverable so when the time comes, you can easily repair or recover your data.
- Control Panel
We provide one of the most comprehensive customer control panels available. Providing maximum control and ease of use, our Control Panel serves as the central management point for your ASPHostPortal account. You’ll use a flexible, powerful hosting control panel that will give you direct control over your web hosting account. Our control panel and systems configuration is fully automated and this means your settings are configured automatically and instantly.
- Excellent Expertise in Technology
The reason we can provide you with a great amount of power, flexibility, and simplicity at such a discounted price is due to incredible efficiencies within our business. We have not just been providing hosting for many clients for years, we have also been researching, developing, and innovating every aspect of our operations, systems, procedures, strategy, management, and teams. Our operations are based on a continual improvement program where we review thousands of systems, operational and management metrics in real-time, to fine-tune every aspect of our operation and activities. We continually train and retrain all people in our teams. We provide all people in our teams with the time, space, and inspiration to research, understand, and explore the Internet in search of greater knowledge. We do this while providing you with the best hosting services for the lowest possible price.
- Data Center
ASPHostPortal modular Tier-3 data center was specifically designed to be a world-class web hosting facility totally dedicated to uncompromised performance and security
- Monitoring Services
From the moment your server is connected to our network it is monitored for connectivity, disk, memory and CPU utilization – as well as hardware failures. Our engineers are alerted to potential issues before they become critical.
- Network
ASPHostPortal has architected its network like no other hosting company. Every facet of our network infrastructure scales to gigabit speeds with no single point of failure.
- Security
Network security and the security of your server are ASPHostPortal’s top priorities. Our security team is constantly monitoring the entire network for unusual or suspicious behavior so that when it is detected we can address the issue before our network or your server is affected.
- Support Services
Engineers staff our data center 24 hours a day, 7 days a week, 365 days a year to manage the network infrastructure and oversee top-of-the-line servers that host our clients’ critical sites and services.