HelloWorld - part 10 advanced properties

From EPESI framework documentation
Jump to: navigation, search

Callbacks

There are a two ways to create callbacks for fields in recordbrowser. One of them is using the set_display_callback function.

$Select = new RBO_Field_Select('Select');
$Select->from('contact')->fields('last_name')->set_visible()->set_display_callback(array('Custom_HelloWorldCommon','display_select'))
$fields[] = $Select;

Fisrt is your modules Common file path and the second parameter is the name of your callback function. To create a callback function you must navigate to your modules Common file. Name it i.e. display_select.

public static function display_select($record, $nolink=false) {
 
 return false;
}

QuickForm

QuickForm field callbacks are used to render fields. More on QuickForm here. In order to create a callback you have to set it for a specific field in you Recordset.php file like so.

$integer = new RBO_Field_Integer('Integer');
$integer->set_visible()->set_QFfield_callback(array('Custom_HelloWorldCommon','QFfield_integer'));
$fields[] = $integer;

The set_QFfield_callback is a method that accepts two prameters. Fisrt is your modules Common file path and the second parameter is the name of your callback function. To create a callback function you must navigate to your modules Common file.

    public static function QFfield_integer(&$form, $field, $label, $mode, $default, $desc){
        if ($mode=='add' || $mode=='edit') {
            $form->addElement('checkbox', $field, $label);
        }else{
            $form->addElement('static', $field, $label);
        }
    }

This will change the integer field into a checkbox if in add or edit mode.


Download: Get full tutorial here