0

I want to do a custom filter that replaces certain text with HTML. Essentially shortcodes as done by Wordpress.

Unfortunately, the Filtered HTML Text Format strips most HTML.

So I created my own Text Format manually and enabled only my own Filter.

Is there a way to do this programmatically in the module.install file?

2 Answers 2

1

Using Features you can export your Text Formats in code and have it automatically configured.

You can configure the filter used for a text format and their order. You can also configure the HTML filter used in the default Filtered HTML text format to allow more HTML elements. So by either allowing the HTML element produced by your filter, and by moving your filter after the HTML filter, you can get your custom filter to work.

0

If you plan on releasing this module for anyone to use, I would not be 'overriding' any currently set/activated formats, as this will cause problems for existing data/nodes/etc. You should simply provide the functionality, and let people activate it as need be. If there are node bodies saved with 'filtered_html' and you disable 'filtered_html', these nodes will not display correctly, and you will make a lot of people unhappy. As such, Drupal probably doesn't provide functions/hooks for doing this (so you can't cause damage to existing data).

If this is just for your own website, you can do anything you want with the right code and manual database changes. I would question the effectiveness of having code doing it, compared to just setting it once manually in the admin.

You can create a filter on install, if that is what you want. See filter_format_save and an example of how to use it in filter.install

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.