Same name and namespace in other branches
  1. 6.x-1.x filter_example/filter_example.module \filter_example

Demonstrates the creation of filters.

This is an example outlining how a module can be used to define a filter to be run on user-submitted content before it is output to the browser.

To show all the capabilities of the filter system, we will define two filters in this module. One will substitute the string "foo" with an administratively-defined replacement string. The other will find a custom XML tag, <time />, and replace it by the current time.

Foo filter

Drupal has several content formats (they are not filters), and in our example the foo replacement can be configured for each one of them, allowing an html or php replacement, so the module includes a settings callback, with options to configure that replacements. Also, a Tips callback will help showing the current replacement for the content type being edited.

Time filter.

This filter is a little trickier to implement than the previous one. Since the input involves special HTML characters (< and >) we have to run the filter before HTML is escaped/stripped by other filters. But we want to use HTML in our result as well, and so if we run this filter first our replacement string could be escaped or stripped. The solution is to use the "prepare" operation to escape the special characters, and to later replace our escaped version in the "process" step.

Parent topics

File

filter_example/filter_example.module, line 7
Module file for filter_example.

Functions

Namesort descending Location Description
filter_example_filter_info filter_example/filter_example.module Implements hook_filter_info().
filter_example_help filter_example/filter_example.module Implements hook_help().
filter_example_menu filter_example/filter_example.module Implements hook_menu().
_filter_example_filter_foo_process filter_example/filter_example.module Foo filter process callback.
_filter_example_filter_foo_settings filter_example/filter_example.module Settings callback for foo filter.
_filter_example_filter_foo_tips filter_example/filter_example.module Filter tips callback for foo filter.
_filter_example_filter_time_prepare filter_example/filter_example.module Time filter prepare callback.
_filter_example_filter_time_process filter_example/filter_example.module Time filter process callback.
_filter_example_filter_time_tips filter_example/filter_example.module Filter tips callback for time filter.
_filter_example_information filter_example/filter_example.module Simply returns a little bit of information about the example.

Classes

Namesort descending Location Description
FilterExampleTestCase filter_example/filter_example.test Functional tests for the Filter Example module.