5

When creating text filter, there are several "type" options (see here). What is the difference between these two?

FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE: Irreversible transformation filters.
FilterInterface::TYPE_TRANSFORM_REVERSIBLE: Reversible transformation filters.

Are there some examples when to use them? For example, when I add a class to a HTML element without any class or specific attribute, is that reversible or irreversible?

2

Per the Filter API docs:

  • Every filter plugin must specify a filter type in its annotation. Filter types were added specifically to support in-place editing. There are four filter types:
    1. FilterInterface::TYPE_MARKUP_LANGUAGE — Non-HTML markup language filters that generate HTML. The filter converts something that's not HTML to HTML in a way that is not compatible with WYSIWYG editing.
    2. FilterInterface::TYPE_HTML_RESTRICTOR — HTML tag and attribute restricting filters to prevent XSS attacks. The filter restricts the HTML allowed, for example, to protect against XSS.
    3. FilterInterface::TYPE_TRANSFORM_REVERSIBLE — Reversible transformation filters. The filter performs a transform for which a WYSIWYG plugin exists to perform the same transformation (and its reverse) client-side. For example, <img data-caption="Druplicon"> may be (reversibly!) transformed to <figure><img><figcaption>Druplicon</figcaption></figure>.
    4. FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE — Irreversible transformation filters. The filter performs a transform for which a WYSIWYG plugin does not exist to perform the transformation client-side (especially, the reverse of it); instead, the WYSIWYG editor displays the unfiltered text. For example, Token Filter.

The type examples given are pretty descriptive of when to use them.

If you CAN take the filtered output and put it back into its original form via a WYSIWYG plugin (e.g. structured markup like XML -> JSON -> XML), use FilterInterface::TYPE_TRANSFORM_REVERSIBLE because the filter output can be reversed.

If you CANNOT take the filtered output and put it back into its original form via a WYSIWYG plugin(e.g. a token filter that prints the node title), use FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE because the filter output cannot be reversed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.