EE2 Functions Reference
Developing a celltype for Matrix is just as easy as creating a fieldtype in EE2. In fact, the first step is to create one.
The only function required to get your fieldtype to show up as an Matrix celltype is display_cell(). Below is a list of all the functions you can add.
Functions at a Glance
display_cell_settings()save_cell_settings()settings_modify_matrix_column()display_cell()validate_cell()save_cell()post_save_cell()delete_rows()
display_cell_settings( $data )
Add custom cell settings to the Matrix Configuration setting within the Edit Field form
Arguments
| Type | Description | |
|---|---|---|
$data |
Array | Previously-saved celltype settings for the column |
Return
Multidimensional array of setting name/HTML pairs
function display_cell_settings( $data )
{
if (! isset($data['maxl'])) $data['maxl'] = '';
if (! isset($data['multiline'])) $data['multiline'] = 'n';
return array(
array(lang('maxl'), form_input('maxl', $data['maxl'], 'class="matrix-textarea"')),
array(lang('multiline'), form_checkbox('multiline', 'y', ($data['multiline'] == 'y')))
);
}
save_cell_settings( $data )
Modify the Matrix cell settings’ post data before it gets saved to the database
Arguments
| Type | Description | |
|---|---|---|
$data |
Array | Post data that came from any inputs you created in display_cell_settings() |
Return
Array with the modified post data
function save_cell_settings( $data )
{
if (! is_numeric($data['maxl'])) $data['maxl'] = 0;
return $data;
}
settings_modify_matrix_column( $data )
Modify the settings of your exp_matrix_data column(s)
Arguments
| Type | Description | |
|---|---|---|
$data |
Array | The data about your column that was inserted into exp_matrix_cols, as well as a “matrix_action” key that describes what Matrix is about to do to it (“add”, “get_data”, or “delete”) |
Return
Array with the settings for your exp_matrix_data columns, which will be passed to dbforge->add_column() upon creation, and dbforge->modify_column() when changed
function settings_modify_matrix_column($data)
{
// decode the col settings
$settings = unserialize(base64_decode($data['col_settings']));
switch ($settings['content'])
{
case 'integer':
return array('col_id_'.$data['col_id'] => array('type' => 'int', 'default' => 0));
case 'numeric':
return array('col_id_'.$data['col_id'] => array('type' => 'float', 'default' => 0));
}
}
display_cell( $data )
Create the custom Matrix cell HTML for the Publish form
Arguments
| Type | Description | |
|---|---|---|
$data |
String | Previously-saved cell data |
Other Variables
| Type | Description | |
|---|---|---|
$this->settings |
Array | Combination of your fieldtype’s global settings and the column settings |
$this->field_id |
String | The Matrix field’s field_id |
$this->field_name |
String | The Matrix field’s field_name, e.g. “field_id_1” |
$this->row_id |
String | The row’s row_id |
$this->col_id |
String | The column’s col_id |
$this->cell_name |
String | The name you give your cell input |
Return
String of HTML to be inserted into the Matrix cell in the Publish form
function display_cell( $data )
{
return '<textarea class="matrix-textarea" name="'.$this->cell_name.'" rows="1">'.$data.'</textarea>';
}
validate_cell( $data )
Validate the Matrix cell’s post data before it gets saved to the database
Arguments
| Type | Description | |
|---|---|---|
$data |
Mixed | The cell’s post data |
Other Variables
| Type | Description | |
|---|---|---|
$this->settings |
Array | Combination of your fieldtype’s global settings, the column settings, and the variables “col_id”, “col_name”, “col_required”, and “row_name” |
Return
Either the validation error, or TRUE if there isn’t an error
function validate_cell( $data )
{
if ($this->settings['col_required'] == 'y') {
if (! $data) {
return lang('col_required');
}
}
return TRUE;
}
save_cell( $data )
Modify the Matrix cell’s post data before it gets saved to the database
Arguments
| Type | Description | |
|---|---|---|
$data |
Mixed | The cell’s post data |
Other Variables
| Type | Description | |
|---|---|---|
$this->settings |
Array | Combination of your fieldtype’s global settings, the column settings, and the variables “col_id”, “col_name”, “col_required”, and “row_name” |
Return
The modified post data
function save_cell( $data )
{
if ($data == ' ') $data = '';
return $data;
}
post_save_cell( $data )
Perform actions after a row has been saved
Arguments
| Type | Description | |
|---|---|---|
$data |
String | The cell’s post data, or the data returned by save_cell() |
Other Variables
| Type | Description | |
|---|---|---|
$this->settings |
Array | Combination of your fieldtype’s global settings, the column settings, the col_id, col_name, row_id, and row_name |
delete_rows( $row_ids )
Perform actions right before rows get deleted
Arguments
| Type | Description | |
|---|---|---|
$row_ids |
Array | The row IDs about to be deleted |