0

I have a content type with a text field that may contain a token from the Media module (that WYSYWIG inserts). This token is typically transformed into HTML by enabling a specific filter for the text format used.

However, I want to create a view for nodes of this type that just strips out the media token entirely. This allows me to show the content w/o any images or captions.

Initially, I thought I could add my own field formatter using hook_field_formatter_info and hook_field_formatter_view, strip out the token right in the formatter, and then use that formatter when rendering the field in the view (views lets you select a formatter, like Default, Trimmed, etc).

The problem there is that by the time hook_field_formatter_view is called, the safe_value for the field is already computed and text has already been run through the input filter (so the token has been transformed).

I wonder if there's a way I can create a new text format that doesn't include the Media token filter and somehow tell views to render the field using that, but it doesn't appear like I can.

1 Answer 1

0

I found an issue concerning something similar to you question on Drupal.org

https://www.drupal.org/node/1113088

There is some module code provided which may be useful to you.

The module looks like it uses a field formatter. Instead of taking out the media tags, it aims to strip out the resulting html tags.

$pattern = array('/<div class="media[^"]+">.+<\/div>/im', '/<p><\/p>/im', '/<p[^>]+><\/p>/im');
  $item['safe_value'] = preg_replace($pattern, '', $item['safe_value']);
1
  • Thanks, I took a look. Unfortunately there is no real solution there other than stripping the HTML out, which I don't want to get involved in.
    – Brian
    Commented Nov 14, 2014 at 20:06

Your Answer

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

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