Add context for check_markup()

Events happening in the community are now at Drupal community events on www.drupal.org.
sun's picture

There's one big problem with the current development of Inline API: Filters do not know what "type of text" they are acting on. For example, the "old" Inline module allowed to embed images/files in a node's content, which are attached to the same node. Because filters don't know what they are doing, Inline needed to run via hook_nodeapi() in the past.

In Inline API, I coded around this limitation, but it's still ugly. So I went ahead and checked, how many times check_markup() is actually invoked in Drupal core. Here's the stunning result:

<?php
/modules/block/block.module(219):      $data['content'] = check_markup($block->body, $block->format, FALSE);
/
modules/comment/comment.module(619):  $text .= '<h2>'. check_plain($comment->subject) .'</h2>'. check_markup($comment->comment, $comment->format, FALSE);
/
modules/comment/comment.module(1524): $comment_values['subject'] = trim(truncate_utf8(decode_entities(strip_tags(check_markup($comment_values['comment'], $comment_values['format']))), 29, TRUE));
/
modules/comment/comment.module(1575): $comment->comment = check_markup($comment->comment, $comment->format, FALSE);
/
modules/node/node.module(1038):       $node->body = check_markup($node->body, $node->format, FALSE);
/
modules/node/node.module(1041):       $node->teaser = check_markup($node->teaser, $node->format, FALSE);
/
modules/profile/profile.module(261):  return check_markup($value);
/
modules/user/user.module(2019):       $comment->signature = check_markup($comment->signature, $comment->format);
?>

A total of 8 instances. So, what we would need for intelligent filtering would be an optionally enhanced function signature:

<?php
function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE, $type = NULL, $object = NULL) {
}
?>

...whereas $type and $object would for example be 'node' and a prepopulated $node object that is passed to all implementations of hook_filter().

This would finally allow us to filter contents with regard to their actual context. Thus, a very simple and silly use-case would be the previously mentioned Inline filter: By typing

[inline:1]

...the filter is able to look up if there are files attached to the current node (context), which one is the first allowed to embed, and transform the tag into a image or file download link.

Benefit for this silly filter alone: The output can be cached.

Comments

Improvements to core

Group categories

Category

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: