Reputation: 3610
In preprocess.node.inc
file, each node type calls its corresponding preprocess function. mytheme_preprocess_node__article
for article, mytheme_preprocess_node__bio
for bio, etc. Is there a function that runs on all these node types? I am trying to avoid using a function that needs to be called on each of these specific preprocess functions. Thanksin advance!
Upvotes: 1
Views: 255
Reputation: 5374
It's simply hook_preprocess_node(&$variables)
. As in MYTHEME_preprocess_node(&$variables)
. This works similar with nearly all elements.
hook_preprocess_page
hook_preprocess_html
hook_preprocess_field
They all are just variants from hook_preprocess_HOOK(&$variables)
where HOOK
gets replaced with whatever element you want.
For certain elements you then can also attach the machine name of an instance to the function's name, to keep your code well structured when you have something that needs to be preprocessed only for certain types.
hook_preprocess_field__FIELD_NAME
hook_preprocess_paragraph__PARAGRAPH_TYPE
For nodes you can also target the view mode, maybe this works for fields as well.
hook_preprocess_node__NODE_TYPE__VIEW_MODE
Upvotes: 0