Now that the basics of the module are in place, let's add our implementation of hook_filter () to creativejuice.module:

* Implementation of hook_filter(). */

function creativejuice_filter($op, $delta = 0, $format = -1, $text = '') { switch ($op) {

return array(0 => t('Creative Juices filter'));

case 'description': return t('Enables users to insert random sentences into their posts.');

case 'settings':

// No settings user interface for this filter. break;

case 'no cache': return FALSE;

case 'prepare': return $text;

case 'process': return preg_replace_callback("|\[juice!\]|i", 'creativejuice_sentence', $text);

default: return $text;

The filter API passes through several stages, from collecting the name of the filter, to caching, to a processing stage where actual manipulation is formed. Let's take a look at those stages or operations by examining creativejuice_filter(). Here's a breakdown of the parameters passed into this hook:

• $op: The operation to be performed. We'll cover this in more detail in the following section.

• $delta: hook_filter() can implement multiple hooks. You use $delta to track the ID of the currently executing filter. $delta is an integer.

• $format: An integer representing which input format is being used.

Depending on the $op parameter, different operations are performed.

Was this article helpful?

+1 0

Post a comment