how to define entity preprocess function My custom module defines a custom entity, which extends the EntityAPIController class. I managed to make it basically working, i.e. displaying fields etc via my custom tpl.php file. But I would like to create a mymodule_preprocess_entity function (as suggested here) to add custom variables to the tpl.php file. But such function is not running (is not called).

Also, when I display this entity, I noticed that the function template_preprocess_entity(&amp;$variables) from entity.module is not running, either.

What else needs to be defined to make the preprocess function for custom entity being called?
I created a general mymodule_preprocess(&amp;$variables, $hook) function and it showed that the specific function name should be mymodule_preprocess_myentity. Where myentity is the proper name of the entity. 

So, this code is working for me:

function mymodule_preprocess(&amp;$variables, $hook) {
  if (isset($variables['elements']['#entity_type'])) { // or maybe check for $hook name
    $function = __FUNCTION__ . '_' . $variables['elements']['#entity_type'];
    if (function_exists($function)) {
      $function($variables, $hook);
    }
  }
}

function mymodule_preprocess_myentity(&amp;$vars) {
  ...
}