1

Is there a way to run a specific block of instructions in hook_node_load only when the node is loaded do be displayed and not when it's loaded in the edit form?

The only way I can imagine is analyzing the url and if the pattern is node/%/edit don't execute the code.

I know I can also use hook_node_view, but in this case I have to add render arrays instead of simple values

1 Answer 1

1

Yes, you'll need to examine the URL for this.

Loading a node is (correctly), completely de-coupled from displaying a node. node_load() doesn't know what you've loaded the node for; it doesn't care, its only responsibility is to prepare the node object.

So the context you're looking for doesn't conceptually exist when hook_node_load() is invoked, as that by definition has to happen before the object is passed to node_view(), and there's no way to signal your desired intent to node_load()

2
  • I can't use menu_get_object() because it seems to call node_load() somewhere and go recursively. But your answer is ok for me. Commented Jul 8, 2014 at 15:06
  • Oh yeah, dumb moment, sorry about that
    – Clive
    Commented Jul 8, 2014 at 15: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.