Appearance
Fieldtype API
The Webservice module provide a set of API methods to make your fieldtype compatible. In order to develop such funtionality, you have to create a fieldtype first. When you`re done, you can add some of the following functions below.
If your Fieldtype only save the data to the channel_data
table, you don`t have to do anything. The Webservice module will support this out of the box. However, if your data need some specific data structure, you have to use this API to make your field compatible with the Webservice module.
You will mostly need the webservice_save
webservice_validate
and webservice_pre_process
- In the
webservice_save
function you can strucutre your data, like on the publish page (see the matrix file as example). - The
webservice_validate
will be your validate function which called before thewebservice_api_save
function. Onfalse
, the data will not be processed. - And the
webservice_pre_process
can be used to strucutre your data on read or search.
As an example of how Matrix data can be submitted with the Webservice module:
'matrix_field' => array(
'rows' => array(
array(
'cell_1' => 'row 1',
'cell_2' => 'row 11',
),
array(
'cell_1' => 'row 2',
'cell_2' => 'row 22'
)
),
'trigger_revisions' => 1
);
This data structure will be converted with the fieldtype API to a correct data structure.
Tag Parameters
Below are the Tag Parameters. Those parameters can be used in the tag described above
field_type
Holds the field type
$this->field_type = '';
field_name
Holds the field name
$this->field_name = '';
field_id
Holds the field id
$this->field_id = 0;
field_data
Holds an array of the field data
$this->field_data = array();
field_settings
Holds an array of the field settings
$this->field_settings = array();
post_data
Holds an array with the data posted to the webservie
$this->post_data = array();
channel_settings
Holds the channel settings as Model
$this->channel_settings = array();
webservice_save()
Preps the data for saving. or you can save your data to your own fields instead.
$data
: null
$is_new
: null
$entry_id
: 0
return
: string
public function webservice_save($data = null, $is_new = false, $entry_id = 0)
{
return $data;
}
webservice_grid_save()
Preps the data for saving. or you can save your data to your own fields instead.
$data
: null
$entry_id
: 0
return
: string
public function webservice_grid_save($data = null, $entry_id = 0)
{
return $data;
}
webservice_validate()
Validates the field input.
$data
: null
$is_new
: null
return
: bool
public function webservice_validate($data = null, $is_new = false)
{
//$this->validate_error = '';
return true;
}
webservice_post_save()
Handles any custom logic after an entry is saved.
$data
: null
$entry
: null
Model object$entry_id
: 0
return
: void
public function webservice_post_save($data = null, $entry = null, $entry_id = 0)
{
}
webservice_pre_process()
Preprocess the data to be returned. Convert any complex data to a nice string or array. The Webservice will convert any Array to a json string.
$data
: null
$free_access
: false
$entry_id
: 0
return
: mixed
public function webservice_pre_process($data = null, $free_access = false, $entry_id = 0)
{
return $data;
}
webservice_delete()
Delete field data. Here you can add some additional deletion for your own fieldtype.
$data
: null
$entry_id
: 0
return
: void
public function webservice_delete($data = null, $entry_id = 0)
{
}