So, to create your custom parameter type and use it in your layout you have to:
1. create a class that extends JElement
Place this file into adminstrator/components/sdp_[component_name]/elements/ directory.
Name this file as [element_type].php
Example of czlonek.php file:
Code: Select all
<?php
defined('_JEXEC') or die();
class JElementCzlonek extends JElement
{
var $_name = 'Czlonek';
function fetchElement($name, $value, &$node, $control_name)
{
$db = &JFactory::getDBO();
$query = "SELECT concat(czlo_nazwisko,' ',czlo_imie) AS text, czlo_id AS value FROM #__czlonkowie"
.' ORDER BY czlo_nazwisko, czlo_imie';
$db->setQuery($query);
$options = $db->loadObjectList();
array_unshift($options, JHTML::_('select.option', '0', '- '.JText::_('Select Czlonek').' -', 'value', 'text'));
return JHTML::_('select.genericlist', $options, ''.$control_name.'['.$name.']', 'class="inputbox"', 'value', 'text', $value, $control_name.$name );
}
}
?>
This class just creates select html tag with all items of 'czlonkowie' table.
2. create XML parameters file for your layout (name this file [layout_name].xml)
Now you can define param with argument type set to your custom type (type="czlonek"). My layout's name is 'default' so paramter's name will be 'default.xml'.
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<layout title="Członek SDP">
<message>
<![CDATA[CZLONEK DESC]]>
</message>
</layout>
<state>
<name>Standard Członek Layout</name>
<description>CZLONEK DESC</description>
<url addpath="/administrator/components/com_sdp/elements">
<param name="id" type="czlonek" section="com_sdp" default="0" label="Czlonek" description="PARAMCZLONEKSELECT" />
</url>
<params>
</params>
</state>
</metadata>
Tag named 'url' defines additional attributes that Joomla! will add to url. Inside this tag I define my custom parameter (remember to set type to your new JElement). Set name attribute of param tag to the name of your additional url parameter.
'Label' and 'description' attributes are not so important. I think that 'section' attribute is not needed in this case - I don't have any sections in my 'czlonkowie' table.
The last thing you have to to is to inform Joomla! where it can find your JElement class. All you have to do is to add addpath attribute to 'url' tag.
addpath="/administrator/components/com_[component_name]/elements"
And that's all. It works for me
.
PS: If there is something wrong with my English please correct me.