View Single Post
Old 12.07.2005, 16:40   #1 (permalink)
ddelaneymdw
Baby Mamber
 
Join Date: Jul 2005
Posts: 1
ddelaneymdw is on a distinguished road
Default Custom Parameter Hack

I modified the mamboxml.php file to include support for using custom parameters in the module setup xml file. I know that you can extend the parameters by extending the mosParameters class. However, no where in the core code (or documentation) can you tell the administration side to use the new class instead of mosParameter without adding functions directly to the mosParameters class.

With that being said, here is an example of the XML setup file for a module with a custom parameter type that will get the categories for newsfeeds:

<params>
<param name="nfcat" type="nfcatlist" default="" label="Cats" description="" />
</params>

<customparam name="nfcatlist">
global $database;
$database->setQuery("SELECT id,name FROM `#__categories`"
. " WHERE section='com_newsfeeds' ORDER BY name");

$options = $database->loadObjectList();
array_unshift($options, mosHTML::makeOption('0','- Select Category -'));

$CustomParamResult = mosHTML::selectList(
$options,"mdwnfcatlist", "class=\"inputbox\"",
'id', 'name',"");
</customparam>

The customparam tage must have a name attribute that matches the type attribute from the param tag above and store output in a variable $CustomParamResult.

Here is the modified render_param function from the mosParameters class:

function renderParam( &$param, $control_name='params' )
{
$result = array();
$name = $param->getAttribute( 'name' );
$label = $param->getAttribute( 'label' );

$value = $this->get( $name, $param->getAttribute( 'default' ) );
$description = $param->getAttribute( 'description' );

$result[0] = $label ? $label : $name;
if ( $result[0] == '@spacer' ) {
$result[0] = '<hr/>';
} else if ( $result[0] ) {
$result[0] .= ':';
}

$type = $param->getAttribute( 'type' );

if (in_array( '_form_' . $type, $this->_methods )) {
$result[1] = call_user_func( array( &$this, '_form_' . $type ), $name, $value, $param, $control_name );
} else {

/************************************************** *********/
/* Customized to include custom parameter handlers in the */
/* xml setup file. (Daniel Delaney, mydigitalway.com) */
/************************************************** *********/

$customParams = & $this->_xmlElem->parentNode->getElementsByTagName("customparam");
if($customParams->getLength() > 0)
{
for($i = 0; $i < $customParams->getLength(); $i++)
{
$customParam = $customParams->item($i);
if($customParam->getAttribute("name") == $type)
{
$i = $customParams->getLength() + 1;
eval($customParam->getText());
$result[1] = $CustomParamResult;
}
else
{
$result[1] = _HANDLER . ' = ' . $type;
}
}
}
else
{
$result[1] = _HANDLER . ' = ' . $type;
}

/************************************************** *********/
}

if ( $description ) {
$result[2] = mosToolTip( $description, $name );
} else {
$result[2] = '';
}

return $result;
}
ddelaneymdw is offline   Reply With Quote
Sponsored Links