I need my filter to be able to know what node it is currently filtering for.
For example I want a filter that replace [nodeinfo] with information about the node. How can that be done? since the hook doesn't show any information about the node.

Comments

nevets’s picture

Filter do not know what node they are working on.

avpaderno’s picture

If you are referring to a filter you are developing, it's enough the module implements hook_nodeapi('load'), which will be called before the node content is rendered. In this way, it can save a copy of the node object in a variable that hook_filter() will then use.

nevets’s picture

Note while it may work most of the time this assumes that a node_load (which triggers hook_nodeapi('load')) is followed by a node_view with out any intervening calls to node_load.

avpaderno’s picture

If the call to node_load() isn't followed by a call to node_view(), then the filter will not be called in; the important is that node_view() is called after node_load(), which should always happens.

nevets’s picture

It is possible thought to do node_load(), node_load() ... node_load() followed by node_view(), node_view() ... node_view(). The point is there is an assumption about the order functions are called in and while it may generally true there is not guarantee it will be always true.

avpaderno’s picture

That is not what Drupal normally does.
You can also suppose that a module could call first node_view(), and then node_load(); in that case, which module would you think it has a bug?

You can then implement hook_nodeapi('view'), and the problem is solved.
Actually, it is more safe to implement hook_nodeapi('view'). In the case node_view() is not called, but the filter is invoked in someway, then the variable will not contain a valid object.