---
title: "Drupal: Exposed"
url: "/articles/drupal-exposed"
type: article
date: 2010-11-01
updated: 2016-04-07
---

# Drupal: Exposed

#  Drupal: Exposed 

 Peeking behind the curtain at what makes Drupal tick

 By

 [  Angie Byron   ](/about/angie-byron) 

 November 1, 2010

  

Here at Lullabot, we've trained hundreds of new Drupalistas in public workshops and on-site private trainings over the years. One of the primary things that people new to Drupal struggle with, once they grasp the basic concept of the hook system and the theme system, is figuring out the "big picture" of what all they actually have to work with to customize their own Drupal sites.

This article will expose a couple of quick core hacks\* that we sometimes use in class to help gain insight into *all* of the hooks, template files, and theme functions that Drupal makes available on a specific page request.

\* Note: Under normal circumstances, we would [*never* recommend that you "hack core"](https://heyrocker.com/hack_core.jpg) (modify core files). However, temporarily, on a local test site, and for educational purposes only, *sometimes* it's okay. Maybe. ;)

## Hooks

The [Drupal API site](http://api.drupal.org/) offers a comprehensive list of [all core hooks](http://api.drupal.org/api/group/hooks/7) that Drupal registers. But unless you have the very simplest of sites, chances are you have one or more contributed modules as well which aren't (currently) displayed on that site. Furthermore, a huge list of what hooks exist doesn't help you when you really want to know what hooks *your* particular Drupal site exposes so that you know where you can cut in and customize Drupal's behaviour.

Fortunately, all hooks in Drupal run through a function called module\_implements(). So you can do a quick hack there to gain insight into what hooks fire on a given page.

In includes/module.inc, find the module\_implements() function (around line 595 in Drupal 7, and 415 in Drupal 6). At the top of the function, just after the line:

  ```php

function module_implements($hook, $sort = FALSE, $reset = FALSE) {
  
```

add:

  ```php

drupal_set_message("hook_$hook");
  
```

This gives you output similar to this (click for full version):

[  ](https://www.lullabot.com/sites/lullabot.com/files/hooks-exposed.png)

   

   

 ![A list of all hooks executed on the given page.](/sites/default/files/styles/wide_xs/public/assets/2016-04/hooks-exposed.png.webp?itok=_VXviNrd "hooks-exposed.png")

Note that there are also hooks that fire *after* the page is displayed, which won't be visible until the next page load.

## Theme system

The [Theme Developer](http://drupal.org/project/devel_themer) module lets you highlight any section of a Drupal page in a [Firebug](https://getfirebug.com/)-esque manner and find out where it comes from. This is incredibly useful when you want to override one specific part of the page.

But sometimes, it can be useful to get a "bird's eye" picture of *all* of the template files and theme functions that make up a given page.

All output on the page is routed through a function called theme() before being presented to the browser. This makes it a nifty place to add some small hacks to gain insight as to what's going on when a page is rendered.

### Template files

In includes/theme.inc in the theme() function, around line 925 (Drupal 7) or 730 (Drupal 6), change:

  ```php

$output = $render_function($template_file, $variables);
  
```

to:

  ```php

    $output = '' . $hook . $extension;
    $output .= $render_function($template_file, $variables);
    $output .= '';
  
```

This simple hack will give you a picture such as this when you reload the page (click for full version):

[  ](https://www.lullabot.com/sites/lullabot.com/files/template-files-exposed.png)

   

   

 ![A list of all hooks executed on the given page.](/sites/default/files/styles/wide_xs/public/assets/2016-04/template-files-exposed.png.webp?itok=Xhq67sRL "template-files-exposed.png")

### Theme functions

A similar hack can show you all the theme functions that create a page. This is not recommended to run with the previous hack or you will have a mess. :)

In includes/theme.inc in the Drupal 7 theme() function, around line 880, change:

  ```php

      $output = $info['function'](#);
  
```

to:

  ```php

      $output = '' . $info['function'];
      $output .= $info['function'](#);
      $output .= '';
  
```

The same hack in Drupal 6's theme() function is around line 655, change:

  ```php

    $output = call_user_func_array($info['function'], $args);
  
```

to:

  ```php

    $output = '' . $info['function'];
    $output .= call_user_func_array($info['function'], $args);
    $output .= '';
  
```

This gives you output similar to this (click for full version):

[  ](https://www.lullabot.com/sites/lullabot.com/files/theme-functions-exposed.png)

   

   

 ![A list of all hooks executed on the given page.](/sites/default/files/styles/wide_xs/public/assets/2016-04/theme-functions-exposed.png.webp?itok=Cdwu7c6A "theme-functions-exposed.png")

## Other suggestions?

Are there any other quick hacks you can suggest for gaining insight into what's going on under Drupal's hood?

 

   You must have JavaScript enabled to use this form.

## Get in touch with us

### Tell us about your project. We'd love to hear from you!

 First Name  

 Last Name  

 Your email address  

 Your organization  

 How you heard about us  

 Tell us more 

     Leave this field blank