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!
Asked
Active
Viewed 233 times
1

qtgye
- 3,580
- 2
- 15
- 30
1 Answers
0
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
- etc.
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
- etc.
For nodes you can also target the view mode, maybe this works for fields as well.
hook_preprocess_node__NODE_TYPE__VIEW_MODE

leymannx
- 5,138
- 5
- 45
- 48