2

In Drupal 6, I have a custom filter, and I would like it to process a field other than the body field, depending on the content type. Is it possible to have it process other fields?

For example, for a page I'd like hook_filter() to be passed the body field as $text, but for a custom content type, I'd like it to be passed a different field. Is this possible?

1 Answer 1

1

It is not possible.
An implementation of hook_filter() is invoked not only for nodes, but also for comments, CCK fields, etc. When it is invoked, the hook doesn't know in which case it is being called, and it only gets the content of the text that needs to be filtered; it cannot understand from that if the text is the body of a node, or it is the content of a comment, nor does it get a reference to the object containing the text that needs to be altered.

The function that calls the implementations of hook_filter() is check_markup(), which is then called by other functions, such as:

As you can see, the input filters are called by user_comment() for rendering the signature of the user, and another module could use the input filters for rendering text for which an administrator user decides which input format users can use.

3
  • Darn. So I will have to do the post processing in hook_nodeapi I guess, or in the theme.
    – Aaron
    Commented Sep 15, 2011 at 0:15
  • If you just want to replace the body field with another field, then you write a module that avoids the body field is rendered, and that users are allowed to enter a value for it.
    – avpaderno
    Commented Sep 15, 2011 at 2:15
  • No I need to to some post processing of arbitrary fields depending on the content type. The answer is hook_nodeapi. It doesn't cache, but that's ok I am not concerned about performance in this scenario, and besides the operation I am doing is fast anyway.
    – Aaron
    Commented Sep 16, 2011 at 14:11

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.