How to call preprocess functions from my custom module I have created a custom module that declares a custom image formatter. Now I need to call the Core image module preprocess function 'template_preprocess_image_formatter'. How would I do that?

I tried to add it in the list of preprocess functions of my custom theme but it doesn't fire unless I clear the cache:

 /**
  * Implements hook_theme().
  */
 function foo_theme() {
    'image_formatter_foo' =&gt; [
          'variables' =&gt; ['item' =&gt; NULL, 'item_attributes' =&gt; NULL, 'image_style' =&gt; NULL],
          'file' =&gt; 'foo.field.inc',
          'preprocess functions' =&gt; [
             'template_preprocess_image',
             'template_preprocess_image_formatter_foo'
          ]
    ],
 }
Looking at template_preprocess_image_formatter, I would try the following code below. 

Replace mymodule with the machine name of the module. This assume foo is the machine name of your image formatter.  

mymodule_preprocess_image(&amp;$variables) {
  /* processing logic */
}

mymodule_preprocess_image_formatter_foo(&amp;$variables) {
  /* processing logic */
}


I also recommend reviewing Drupal 8's Core Image module as it has some of the files that call the hooks you need. 


image.field.inc contains template_preprocess_image_formatter
template_preprocess_image