Due little documentation about seblod development, here a little note tips regarding JCckDev::renderForm

What is renderForm anyway ?

If you build a field plugin, you might want to set parameter for it. I'm not refer to how field display in Admin or Site Form, but how field get setup. Perhaps a visual screenshot would help:

Seblod Field Setting


So, a seblod field that you see in Admin/Site Form (i call it Form Field) is made by another field (i call it Construction Field). Now, what i'm shere here is refer to Construction Field.

Construction Field is use in edit.php, of tmpl folder in cck plugin field:

JcckDev::renderForm() is use to display parameter to construct your Form Field

An example of JcckDev::renderForm usage, would be like this:

echo JCckDev::renderForm( 'core_defaultvalue', $this->item->defaultvalue, $config );

Let's see how we can understand and do little bit 'magic' with this function alone

renderForm() is declared on libraries/cms/cck/dev.php, but before we dig into explanation of its parameter, i would like you to know that field setting (and behavior) is related with '#__cck_core_fields' table.

So let's start:

public static function renderForm( $field, $value, &$config = array( 'doValidation' => 2 ), $override = array(), $inherit = array(), $class = '' )

$field : field name 
$value : Default value (please aware the where the value stored)
$config : some configration, i use to live it as default and i rarely find any new setting here in other fields
$override : some override with default configuration, the most 'magic' begin here
$inherit : Well.. no idea, i use to live it as default which 'array ()', you can set array('name' => somevalue, 'name' => somevalue,'after'=>somevalue )
$class: set specific class


 For example, let's built a default twitter username parameter on top of core_defaultvalue field

1. Copy Paste and override the label

echo JCckDev::renderForm( 'core_defaultvalue', $this->item->defaultvalue, $config, array('label'=>'Twitter Username' );

2. Change storage field

echo JCckDev::renderForm( 'core_defaultvalue', @$options2['defaulttwitter'], $config, array('label'=>'Twitter Username','storage_field'=>'json[options2][defaulttwitter]' );

 $option2 is the recommended way to have custom parameter, if you like to use/override other field, please see #__cck_core_fields and see other field (but beware of breaking core seblod functionality, if you unsure, use options2)

3 Add CSS Class, 'twitterusername' (optional)

echo JCckDev::renderForm( 'core_defaultvalue', @$options2['defaulttwitter'], $config, array('label'=>'Twitter Username','storage_field'=>'json[options2][defaulttwitter]',array(),'twitterusername' );

note: notice i use 'array()' to send null array for $inherit parameter


You like to know on how seblod field works ? Click this Seblod Field Behavior Article (coming soon)

Like to improve and make this article better to readl ? Email me : This email address is being protected from spambots. You need JavaScript enabled to view it.