Adding full hook support to your theme

Here are some tricks to adding full hook support to your theme
Drupal article - Adding full hook support to your theme

Drupal 7 has been around for quite a while, and with it a bunch of no-brainer rules and guidelines. One of these little gems floating amongst the detritus of my Drupal miscellany: "In Drupal 7 themes can implement hooks". I pulled this one out earlier today before proceeding to spend 40 minutes trying to figure out why a theme couldn't implement hook_panels_pre_render(). Had I been wrong about this for so long? Surely not. But a closer look at module_list() said it could be so.

Eventually normalcy was restored. Most of the hooks implememted at the theme level tend to be preprocessing and alters. drupal_alter() has custom logic to handle theme implementations.

So back to the problem: how to coerce our theme to implement hook_panels_pre_render()?


/**
 * Implements hook_module_implements_alter();
 */
function mytheme_module_implements_alter(&$implementations, $hook) {
  switch($hook) {
    case 'init':
    case 'panels_post_render':
    case 'panels_post_render':
    case 'kitchen_sink':
      // Indicate that our theme implements this hook. 
      $implementations['mytheme'] = FALSE;
  }
}

/**
 * Implements hook_panels_pre_render();
 */
function mytheme_panels_pre_render() {
  dpm("huzza!");
}

 

The Author

James Harvey

Chief Development Officer