Buy now for just €35.00
| Compatibility: | EE1, EE2 |
|---|---|
| Latest release: | 2.2.1 (released 2012-04-24) |
| Licensing: | Commercial License Agreement |
Anatomy of a Variable Type
Below is the skeleton of a variable type, containing all possible properties and methods.
class My_new_type extends Low_variables_type {
public $info = array();
public $assets = array();
public $language_files = array();
public $default_settings = array();
public function display_input($var_id, $var_data, $var_settings)
{
// ...
}
public function save_input($var_id, $var_data, $var_settings)
{
// ...
}
public function post_save_input($var_id, $var_data, $var_settings)
{
// ...
}
public function display_output($tagdata, $row)
{
// ...
}
public function display_settings($var_id, $var_settings)
{
// ...
}
public function save_settings($var_id, $var_settings)
{
// ...
}
public function post_save_settings($var_id, $var_settings)
{
// ...
}
public function delete($var_id)
{
// ...
}
}
Properties
$info
(array) — contains basic information about the Variable Type.
public $info = array(
'name' => 'My variable type name',
'version' => '1.0.0'
);
$assets
(array) — if the variable type has external css and/or javascript, this contains their references. Use the keys css and js,
and set their values to the relative path to the assets. The files should be put inside the /themes/low_variables/types/your_variable_type/ folder.
If you need to load multiple files, use an array as value.
public $assets = array(
'css' => 'css/extra_styles.css',
'js' => array(
'js/my_custom_plugin.js',
'js/another_plugin.js'
)
);
$language_files
(array) — if the variable type uses any language file, this contains their references. You can load any of the available language files by calling their name.
public $language_files = array(
'my_variable_type_name',
'upload',
'image_lib'
);
$default_settings
(array) — if the variable type has settings, this contains all settings and their default values.
public $default_settings = array(
'height' => '100',
'member_groups' => array(1),
'separator' => 'pipe'
);
Methods
display_input
Use this method to display the input field used to enter the value of the variable.
Note: The name of the input field should be var[{$var_id}].
Arguments
$var_id(int) — the ID of the variable.$var_data(string) — the current value the variable.$var_settings(array or bool) — the current type settingsFALSEif no settings exist.
Returns
A string containing the HTML to display the input field of the given variable.
save_input
This method is called just before the value of the variable is saved to the database. Use it to alter or evaluate the value before it is saved.
Arguments
$var_id(int) — the ID of the variable.$var_data(string) — the posted value the variable.$var_settings(array or bool) — the current type settingsFALSEif no settings exist.
Returns
A string containing the new value of the variable or FALSE if the variable must not be saved (skipped). If you return
FALSE, be sure to enter a value into $this->error_msg for displaying an error message.
post_save_input (v1.3.7+)
This method is called after the value of the variable is saved to the database. Use it for extra processing after it is saved.
Arguments
$var_id(int) — the ID of the variable.$var_data(string) — the posted value the variable.$var_settings(array or bool) — the current type settingsFALSEif no settings exist.
Returns
NULL
display_output
Use this method to display custom output of the variable value. It is used by the exp:low_variables:parse, exp:low_variables:single and exp:low_variables:pair template tags.
Arguments
$tagdata(string) — the template tagdata.$row(array) — array containing the current variable details. Keys:variable_id,variable_name,variable_data,variable_label,variable_typeandvariable_settings.
Returns
A string with modified tagdata.
display_settings
If your variable type has settings, use this to display them in the Manage Variable form.
Note: Use the function $this->input_name('my_custom_setting') for the setting input names.
Arguments
$var_id(int or string) — the ID of the variable ornewif the variable is new.$var_settings(array or bool) — the current type settingsFALSEif no settings exist.
Returns
An array containing the HTML of all the settings. Per setting, use an array with two values; the first one for the setting label, the second one for the setting input field.
save_settings
This method is called just before the settings of a (new) variable is saved to the database. Use it to alter or evaluate the settings before they are saved.
Arguments
$var_id(int or string) — the ID of the variable ornewif the variable is new.$var_settings(array or bool) — the current type settingsFALSEif no settings exist.
Returns
An array containing the (modified) settings.
post_save_settings (v2.2.0+)
This method is called just after the settings of a (new) variable is saved to the database. Use it for extra processing after it is saved.
Arguments
$var_id(int) — the ID of the variable.$var_settings(array or bool) — the current type settingsFALSEif no settings exist.
Returns
NULL
delete (v2.2.0+)
This method is called just before a variable is deleted. Use it for extra processing before it is deleted permanently.
Arguments
$var_id(int) — the ID of the variable.
Returns
NULL