Custom parametersAs the release of Joomla 1.6 stable comes closer we have started to migrate our extensions to the new framework. We came accross some challenges and because there is very few documentation about some changes in 1.6 we'd like to share our findings with the hope that they will be useful for one or another developer.

So here is how you can create custom parameters for your plugins:

The first thing I'd like to point out is the general xml structure of params in 1.6: All params are wrapped into <config> tags. Then what was earlier the <params> tag is now <fields> with the attribute name="params". Inside the fields we can create as many fieldsets as we like to group the params in those handy drop down sliders. The name attribute will appear as the slider's title. {codecitation style="brush:xml;"}

<field name="myParam" type="text" default="" label="My Param" description="A regular free text param." />

{/codecitation} The first thing when it comes to custom parameters is to reference the field path in the fields tag like this: {codecitation}<fields name="params" addfieldpath="/plugins/system/myplug/myplug/elements">{/codecitation} This allows us to create our own functions to override the Joomla core parameter creation. To create a custom parameter we need to define it just like any other parameter. Let's create a title box with some additional information: {codecitation}<field name="@title" type="title" default="" label="My custom param" description="This is a description for my custom param!" url="http://www.freakedout.de" showSave="1" showApply="1" />{/codecitation} As we have referenced the field path we need to create that folder an put some files in it: /plugins/system/myplug/myplug/elements
Our custom param has the type attribute "title" so we need to create a file called title.php in the elements folder. This is the basic structure of this file: {codecitation}<?php defined('_JEXEC') or die( 'Restricted access' ); class JFormFieldTitle extends JFormField { function getLabel() { return ''; } function getInput() { return ''; } } ?> {/codecitation} Note that the class name is JFormFieldTitle where the last bit must be the same as the params type attribute, in this case "title".

Now all that is left to do is fill the functions with some code to retrieve the attributes and generate the output:

We don't want to display a label next to the param so we leave getLabel() as it is and return an empty string.

We use getInput() to create our html element: {codecitation} function getInput() { // initialise the var that will contain our output $html = ''; // get the attributes and assign them to vars if they are set $title = ( isset( $this->element['label'] ) ) ? $this->element['label'] : ''; $url = ( isset( $this->element['url'] ) ) ? $this->element['url'] : ''; $description = ( isset( $this->element['description'] ) ) ? $this->element['description'] : ''; $showApply = ( isset( $this->element['showApply'] ) ) ? $this->element['showApply'] : 0; $showSave = ( isset( $this->element['showSave'] ) ) ? $this->element['showSave'] : 0; // now let's process each attribute // if title is set we decode html entities and apply JText to allow Joomla pull available translations from language files if ( $title ) { $title = html_entity_decode( JText::_( $title ) ); } // if url is set we can wrap the title into an hyperlink if ( $url ) { $urlFront = ''; $urlBack = ''; } else { $urlFront = $urlBack = ''; } // also decode the description and make it translatable if ( $description ) { $description = html_entity_decode( JText::_( $description ) ); } // now we can start putting it all together $html .= '

'; $html .= '

'.$urlFront.$title.$urlBack.'

'; if ( $description ) { $html .= $description; } // create save and apply buttons if the attributes are set to 1 (of course we need to put those images into the referenced folder) if ( $showSave ) { $showSave = ''.JText::_( 'Save' ).''; $html .= $showSave; } if ( $showApply ) { $showApply = ''.JText::_( 'Apply' ).''; $html .= $showApply; } // clear all floats, close the divs and return the output $html .= '
 

'; return $html; } {/codecitation}