Flexifilter's API
Flexifilter was created to provide a better method for creating filters, and although it can build nearly any type of filter necessary, it was also created with extensibility in mind. Therefore, Flexifilter has several hooks and API functions that are useful for filter-type modules.
Flexifilter's Hooks
hook_flexifilters allows modules to define default flexifilters. A array should be returned, with each value of the array corresponding to an exported flexifilter (as an array itself).
<?php
function hook_flexifilters() {
return array(
// Exported flexifilter array here.
,
// Another exported flexifilter array here.
);
}
?>
hook_flexifilter_components allows modules to describe the components in their flexifilters.
A description of hook_flexifilter_components, from the API.txt file:
<?php
/**
* Implementation of hook_flexifilter_components()
*
* @return An array of components to be used by the Flexifilter module. The keys of this array
* are unique identifiers for the component (called the component class), and the values of the
* array are again arrays, with the following keys:
* - label : A human readable name for the component
* - description (optional) : A human readable description of what the component does (defaults to none)
* - is_container (optional) : TRUE if any of the #contains_ fields are TRUE (set automatically)
* - contains_condition (optional) : TRUE if the component has a condition associated with it (defaults to FALSE)
* - contains_components (optional) : TRUE if the component has children components (defaults to FALSE)
* - callback : A callback function which implements the component
* - callback_arguments (optional) : An array of arguments to pass to the callback function (defaults to none)
* - group (optional) : A human readable name of the group that the component belongs to (defaults to "Other")
* - step : The step in which this is to be performed. Either 'both', 'either', 'process', or 'prepare'.
* - If 'either' is specified, it will default to process, and the user will not be given the option to change it
* unless they have "show advanced options" checked.
*/
?>
hook_flexifilter_conditions allows modules to describe the conditions for their flexifilters. hook_flexifilter_conditions works similarly to hook_flexifilter_components, except there is no step attribute.
Useful API Functions
flexifilter_install_flexifilters should be used in your modules implementation of hook_install. Example:
<?php
mymodule_install() {
flexifilter_install_flexifilters('mymodule');
}
?>
<?php
/**
* API function: installs flexifilters.
*
* @param $module - The name of the module whose flexifilters should be installed.
* @param $flexifilters - Optional. An array of flexifilters to be installed. If passed in, $module is irrelevant.
*/
function flexifilter_install_flexifilters($module, $flexifilters = NULL) {
if (is_null($flexifilters)) {
$flexifilters = module_invoke($module, 'flexifilters');
}
foreach ($flexifilters as $flexifilter) {
$fid = flexifilter_save_filter($flexifilter);
drupal_set_message(t('The !url flexifilter has been saved.', array('!url' => l($flexifilter['label'], "admin/build/flexifilters/$fid"))));
watchdog('flexifilter', 'The !url flexifilter has been saved.', array('!url' => l($flexifilter['label'], "admin/build/flexifilters/$fid")));
}
}
?>
flexifilter_invoke_condition($condition, $op, $text) invokes the condition specified in 'condition' with $op and $text. It will return either TRUE or FALSE, depending on what the condition returned.
flexifilter_invoke_components($component, $op, $text) invokes the component specified in 'component' with $op and $text.
flexifilter_components_involve_step($components, $step) will return TRUE if any of the components in the components array will run in the current step 'process' or 'prepare'.
Implementing Flexifilter
The API.txt file that is included in the flexifilter module folder has the latest and most up to date information on how to properly implement flexifilter in your module. Also, for a real world example, look at the Flexifilter Cite module.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion