By Mgccl on
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
Filter do not know what node
Filter do not know what node they are working on.
---
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 thathook_filter()will then use.Note while it may work most
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.
---
If the call to
node_load()isn't followed by a call tonode_view(), then the filter will not be called in; the important is thatnode_view()is called afternode_load(), which should always happens.It is possible thought to do
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.
---
That is not what Drupal normally does.
You can also suppose that a module could call first
node_view(), and thennode_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 casenode_view()is not called, but the filter is invoked in someway, then the variable will not contain a valid object.