How to make mymodule_preprocess_node run only once? We have a custom mymodule that calls mymodule_preprocess_node(&amp;$variables) hook. When we add ksm($variables); to the hook, we are finding the message is printed multiple times (average has been 5x). 

How to make mymodule_preprocess_node run only one time?

I am needing to run this hook because I want to check to see if a field is populated with some value then perform some other logic. 

Example:

function mymodule_preprocess_node(&amp;$variables) {
  $node = $variables['node'];
  if(isset($node-&gt;get('field_link'))) {
    // perform some logic. 

   ksm('in here'); // printed multiple times. 
  }
}
I found the issue. As @Kevin mentioned, it was being called for every node being rendered. I added a condition to check the view more as well and it is being called just one time now. 

function mymodule_preprocess_node(&amp;$variables) {
  $node = $variables['node'];
  if(isset($node-&gt;get('field_link')) &amp;&amp; $variables['elements']['#view_mode'] == 'my_view_mode') {
    // perform some logic. 

   ksm('in here'); // printed once as expected 
  }
}