In order to develop an element for Content Elements, you need to create EE2 fieldtype first. Once done, you need will to add the following functions:
Additional functions (optional):
display_element($data)
@param mixed $data – data stored in the element
@return string – element HTML markup
function display_element($data)
{
$field = array(
'name' => $this->element_name,
'value' => $data,
);
return form_text($field);
}
The following variables are available:
$this->settings – array with element settings
$this->field_name – name of the <input> field
replace_element_tag($data, $params = array(), $tagdata)
@param mixed $data – data stored in the element
@param array $params – parameters taken from the used tag
@param string $tagdata – HTML markup to be replaced with output
@return – HTML output
Used to render the element data (contents) on the front-end.
$this->settings – array with element settings
$this->element_title – name of the element (given upon creating it)
$this->element_id – element identifier (hash) assigned by the system
display_element_settings($settings)
@param array $settings – array with element settings
@return string/array – multi-dimensional array of setting name and HTML pairs
function display_element_settings($data){
return array(
array(lang('rows'), form_input('maxl', @$data['rows'])),
array(lang('cols'), form_input('maxl', @$data['maxl'])),
);
}
Used to render the element settings in Content Element fieldtype settings.
save_element_settings($settings)
@param array $settings – array with submitted data
@return array
Allows to modify submitted data before they are stored in the database. Good for modifying an input.
function save_element_settings( $data )
{
if ($data['rows'] > 10) $data['rows'] = 10;
return $data;
}
validate_element($data)
@param mixed $data – data user has submitted on the publish page
@return mixed – TRUE if validation is OK, or error message
Used to validate the data being submitted.
function validate_element($data){
if (!is_number($data))
{
return 'Error: Age must be number';
}
return TRUE;
}
save_element($data)
@param mixed $data – data user had submitted before before they were stored in the database
@return string – data to be stored in the database
function save_element($data)
{
//serialize array
return serialize($data);
}
The following variables are available:
$this->settings – array with element settings
$this->field_name – name of the <input> field
post_save_element($data)
@param mixed $data – data user had submitted before before they were stored in the database
@return void
Used to additionally process the submitted data. The following variables are available:
$this->settings – array with element settings
$this->field_name – name of the <input> field
$this->element_title – name of the element (given upon creating it)
$this->element_id – element identifier (hash) assigned by the system
preview_element($data)
@param mixed $data – data stored in the element
@return – HTML
Used to display element preview in Control Panel after submitting the publish form. The following variables are available:
$this->settings – array with element settings
$this->element_title – name of the element (given upon creating it)
$this->element_id – element identifier (hash) assigned by the system