This module provides a simple input filter which helps creating collapsible fieldsets without efforts.
The collapsible fieldsets are just the same as everywhere else in Drupal, especially forms. They do trigger the same Javascript which is used by Drupal core. Hence, this module forces "collapse.js" and "form.js" to be loaded with any page request (as post-filter script dependencies are unachievable in Drupal at this time). However, they are included in almost any page anyway and so they do not hurt, even less, if you enable JS aggregation.
I wrote this filter to achieve nice, stylable hint boxes for some online tutorials without re-coding them by hand over and over again. You may find your own use cases.
Usage
Once you add this filter to a text format's filter chain and use the pre-set "example" type, it will turn code like
<fieldset type="example">lorem ipsum</fieldset>
into
<fieldset class="collapsible collapsed formatted-fieldset example">
<legend><span class="fieldset-legend">Example</span></legend>
<div class="fieldset-wrapper">
lorem ipsum
</div>
</fieldset>
Configuration and styling
- You may define unlimited sets (called "types") which pre-set each type's CSS class name, a dedicated text label and additional options (like collapsible (or not), initial status (collapsed or not)...
- Use the per-format option CSS classes and each type's class name for styling different fieldset types.
Background
The filter runs with two passes: The <fieldset...> tags are first escaped into [fieldset...] tags (so HTML filters would not remove them) and converted to the final fieldsets in the second pass.
The advantage of using native HTML instead of pseudo tags all over is that, once you remove this filter, most of your content will remain readable (as fieldset tags are valid HTML and will either be stripped out or just render to, well, a fieldset).
Caveats and tricks
- This filter must run after any HTML/Wysiwyg filters, otherwise the fieldset tags or their attributes might be removed in the second pass.
- Also it must run before filters like typogrify to make sure that quotes are not turned into typographic ones.
- You may change the tag name from "fieldset" to whatever you wish, e.g.
<switchbox></switchbox>if that better fits with your filter chain. - All these settings are done on a per-format basis.
Known issues
If you use PHP-FPM as a fast CGI server backend, you may run into random "Internal server errors" and WSODs after enabling the module. At least this is what I did first, while the module ran flawlessly in any mod_php setup. I do not really know the cause, maybe it is something memory related (most complex thing the module does is use some regex). Some research pointed out it might be a bug in some PHP(-FPM) releases. If someone has more knowledge/information, please let me know.
However, I could solve this persistantly by simply restarting the php-fpm service.
Hope you like it!
Project information
- Project categories: Content editing experience
9 sites report using this module
- Created by doitDave on , updated
Stable releases for this project are covered by the security advisory policy.
There are currently no supported stable releases.
