A simple fieldtype

At a minimum, a fieldtype extension must include an $info array with basic information about the fieldtype, and a function called display_field.

If you want your fieldtype to double as an FF Matrix cell, you will also need a function called display_cell.

Here’s a sample “Checkbox” fieldtype, based on the one that comes bundled with FieldFrame:

class Checkbox extends Fieldframe_Fieldtype {
 
    var $info = array(
        'name'             => 'Checkbox',
        'version'          => '1.0.0',
        'desc'             => 'Provides as single checkbox field type',
        'docs_url'         => 'http://brandon-kelly.com/',
        'versions_xml_url' => 'http://brandon-kelly.com/downloads/versions.xml'
    );
 
    function display_field($field_name, $field_data)
    {
        global $DSP;
        $checked = ($field_data == 'y') ? 1 : 0;
        return $DSP->input_checkbox($field_name, 'y', $checked);
    }
 
    function display_cell($cell_name, $cell_data)
    {
        return $this->display_field($cell_name, $cell_data);
    }
 
}

The $info array holds all of the key descriptive information about the fieldtype:

  • name — The name of the fieldtype, which appears in the Fieldtype Manager and the Edit Field form
  • version — The version of the fieldtype
  • desc — A brief description of the fieldtype, which appears in the Fieldtype Manager
  • docs_url — The URL that the fieldtype’s Documentation link within the Fieldtype Manager will point to
  • versions_xml_url — The URL to your XML file that LG Addon Updater will check for updates