1

I have to remove some elements from a node before show it, but I can't understand where it's better to put the code. Mainly I can't understand the differences between hook_node_view_alter and hook_preprocess_node. It seems they do the same thing as they receive a render array as parameter.

I think the best option should be to use the hook_node_view but it isn't the right way to do this because in this hook only $node->content is editable.

1
  • Yes, sure I meant hook_preprocess_node. I changed it in the question for better indexing. Commented Oct 15, 2013 at 7:44

1 Answer 1

1

hook_preprocess_node is more generic, and thus more limited, and happens after hook_node_view_alter.

Both operate on the similar array, basically, but hook_node_view_alter operates at earlier stage. So, first reason is ordering of actions, second is accessing a bit different data sets, as they changes between stages of execution. dpr() or var_dump() their arguments to see exact differences. That's all. Nothing much to it, really.

3
  • Just to note, my answer was posted when there was template_preprocess_node in a question, not hook_preprocess_node...
    – Mołot
    Commented Oct 15, 2013 at 7:49
  • Sure I'm sorry if my change was a problem for you. By the way, can you explain me the main difference between these two hooks? Thank you. Commented Oct 16, 2013 at 6:55
  • 1
    @LateAtNight Answer updated
    – Mołot
    Commented Oct 16, 2013 at 6:58

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.