Pull Quotes in Drupal 7 – Using hook_filter_info()

I recently wrote a post called Pull Quotes Shortcodes via Custom Filters in Drupal 7 . This was a good solution, but I decided I wanted a little more flexibility in my filter (like being able to specify attributes in any order) and I wanted to get rid of the required [/pullquote] closing tag. Custom Filter has its limitations (and working through the gui would’ve been a PITA), so I fired up Vim and made a custom filter using hook_filter_info().

Here is part of my original description of what I needed:

I’ve been working on a Drupal 7 site that requires some nicely-formatted pull quotes. The site editors need the ability to add them to their content easily through the “filtered” text fields throughout the site (e.g., body).

End Result

The shortcode (this term makes the most sense here) I want to offer to the editor looks like this:

The HTML output I’d like to render (given the example above) looks like this:

Rather than explain the different options I’d like to offer, I’ll just include this screenshot of the help text that the editors will see:


Setup and Configuration

Step 1: Create the filter. In this example I’m using a module called “mymodule”. The comments in the code should provide you with an explanation of what’s going on. I’m using hook_filter_info() from the Filter api (this is part of Drupal 7 core; I’d be surprised if you don’t have this enabled already).

Step 2: Add the custom filter to the text formats in which you want to use pull quotes. For example, to add this new filter to the Full HTML text format I went to Admin » Configuration » Content authoring » Text formats » Full HTML, then I checked the Pull quote filter checkbox and made sure the filter was in the right position in the filter processing order (in my case, at the top).

Step 3: Try it out! Hit a content type that allows you to use a text format you added the filter to, and try one of the examples.

Step 4: Add styling to your stylesheets to make the output look pretty!


Well, there you have it: another “custom” solution for nice-looking, easy-to-add pull quotes.

Leave a Reply

Your email address will not be published.