Extension Hooks
If your fieldtype extension needs to do something outside of the provided functions, you can still tap into ExpressionEngine’s powerful extension hooks. In fact, FieldFrame goes a long way toward making them even easier to use in a fieldtype than in a normal extension.
Defining Your Hooks
First, list out which hooks you want to use via an array called $hooks:
class Checkbox extends Fieldframe_Fieldtype {
var $info = array( /* ... */ );
var $hooks = array(
'edit_entries_modify_tableheader',
'edit_entries_modify_tablerow'
);
// ...
}
By default, FieldFrame will give your hook a priority of 10, and will assume the function you want to tie it to has the same name as the hook itself. If either of those are not the case, simply treat the hook name as a key to an array with the proper settings:
// ...
var $hooks = array(
'edit_entries_modify_tableheader' => array('priority' => 1, 'method' => 'feels_good'),
'edit_entries_modify_tablerow'
);
// ...
Writing Your Functions
Now that you’ve defined which hooks you want to use, you need to add the functions that use them. You approach this much in the same way that you would a normal hook function, with one significant difference: if the hook returns data, you grab the previously-returned data a bit differently:
// ...
function edit_entries_modify_tablerow($o)
{
$o = $this->get_last_call($o);
// ...
return $o;
}
// ...
“get_last_call()” is a function that comes along with the Fieldframe_Fieldtype class that your fieldtype extends. You pass it one argument: the variable that your hook function was sent that your function is modifying. If your hook doesn’t send such a variable (like publish_form_headers), you can pass a default value, or leave it blank.
The reason that this function exists is because $EXT->last_call() doesn’t necessarily account for the last called fieldtype hook function. Also, it’s just way more convenient than the traditional way.
Telling FieldFrame About Changes to $hooks
FieldFrame will check to see if your $hooks array has changed whenever your fieldtype’s version number has changed. So, if you’re having trouble getting FieldFrame to activate your new hooks, try updating your version number.