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.

  • Yes, sure I meant hook_preprocess_node. I changed it in the question for better indexing. – LateAtNight Oct 15 '13 at 7:44
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.

  • Just to note, my answer was posted when there was template_preprocess_node in a question, not hook_preprocess_node... – Mołot Oct 15 '13 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. – LateAtNight Oct 16 '13 at 6:55
  • 1
    @LateAtNight Answer updated – Mołot Oct 16 '13 at 6:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.