[Drupal] New filter in Drupal 7

| | 1 min read

By default Drupal supports different text formats for the body of the node. On selecting a particular format, it processes the text entered and output the result.

New filter

To implement a new filter for in drupal 7, it provides a hook as hook_filter_info().

Using this hook, we can create a new filter, see the example below,

/**
 * Implements hook_filter_info().
 */
function landing_page_filter_info() {
  $filters = array();
  $filters['new_format'] = array(
    'title' => t('Landing page filter'),
    'process callback' => 'new_format_filter_process',
    'tips callback' => 'new_format_filter_tips',
    'cache' => FALSE,
  );
  return $filters;
}

Here it will create a new filter called new_format. To see the new format created, try to add a new text format, the filter created must list under the filters. The process callback is the function called on selecting the text format and saving the node. The tips callback return display the help text next to the text format on the expected format of text.

Please fell free to share your thoughts and doubts regarding this here.