Joomla 1.6 custom parameters

Monday, 05 July 2010
Rate this item
(0 votes)

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.

<fieldset><field name="myParam" type="text" default="" label="My Param" description="A regular free text param." /></fieldset>
The first thing when it comes to custom parameters is to reference the field path in the fields tag like this:
<fields name="params" addfieldpath="/plugins/system/myplug/myplug/elements">
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:
<field name="@title" type="title" default="" label="My custom param" description="This is a description for my custom param!" url="" showSave="1" showApply="1" />
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:
<?php defined('_JEXEC') or die( 'Restricted access' ); class JFormFieldTitle extends JFormField { function getLabel() { return ''; } function getInput() { return ''; } } ?> 
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:

 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 = '<a href="'.$url.'" target="_blank" title="'.$title.'">'; $urlBack = '</a>'; } 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 .= '
<h4 style="margin: 5px 0pt 0pt; width: auto; float: left;">'.$urlFront.$title.$urlBack.'</h4>
'; 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 = '<a href="#" title="'.JText::_( 'Save' ).'" onclick="submitbutton(\'\');" style="float: right;"><img src="'.JURI::root().'plugins/system/myplug/myplug/elements/images/save.png" border="0" alt="'.JText::_( 'Save' ).'" align="right" /></a>'; $html .= $showSave; } if ( $showApply ) { $showApply = '<a href="#" title="'.JText::_( 'Apply' ).'" onclick="submitbutton(\'plugin.apply\');" style="float: right;"><img src="'.JURI::root().'plugins/system/myplug/myplug/elements/images/apply.png" border="0" alt="'.JText::_( 'Apply' ).'" align="right" /></a>'; $html .= $showApply; } // clear all floats, close the divs and return the output $html .= '

'; return $html; } 

Read 3407 times
Login to post comments

Why freaked out?

The name "freaked out" does not symbolize our mental state but rather the approach to give our clients the unexpected - the extra edge - over their competitors to be successful in bussiness. That might appear from time to time a little freaked out but if you want plain vanilla work there are plenty of companies out there offering that. We go beyond.


If you have any questions or comments about our extensions or need help to get started please use our forums or the contact form. We will get back to you shortly!

Pro subscribers are advised to use the ticket system to receive premium support.


freaked out
53, Għaxqet L-Għajn
Triq Carini
Santa Venera - Malta

Email: This email address is being protected from spambots. You need JavaScript enabled to view it. uses cookies!

This website uses cookies to provide user authentication and improve your user experience. Please indicate whether you consent to our site placing these cookies on your device. We are not using cookies for marketing purposes. For more information visit our privacy policy

I agree
Copyright © 2010 - 2023 - All rights reserved