18.10.2016 Views

Drupal 7 Module Development

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Drupal</strong>’s Theme Layer<br />

There are actually two different ways you can make an implementation (which<br />

we will discuss later), but for now we'll only talk about the simplest method for<br />

module developers—theme functions. When you call theme(), it will look for a<br />

default theme function named theme_HOOKNAME and for an optional theme override<br />

function called THEMENAME_HOOKNAME. If you dig into <strong>Drupal</strong>'s internals, you'll find<br />

a theme_item_list() inside includes.inc or theme.inc. This is <strong>Drupal</strong>'s default<br />

theme implementation for an item_list. If our active theme was Bartik, and if<br />

Bartik implemented a theme override called bartik_item_list(), then theme()<br />

would use the Bartik theme's implementation instead of the default one.<br />

The preceding figure shows one piece of data as it passes through a module and a<br />

theme. However, in order for you to understand the full power of <strong>Drupal</strong>'s theme<br />

layer, you also need to understand how the entire page is built.<br />

However, since all of the active theme's modifications occur after any module<br />

modifications, from a module developer's perspective, all of this theme inheritance<br />

is transparent. Since modules don't need to know anything about the structure of<br />

the theme and its ancestry, we'll simply talk about "the theme" in this book. Just be<br />

aware that the actual theme may be more complex.<br />

Base themes and sub-themes<br />

If you've previously read anything about <strong>Drupal</strong> theming, you've<br />

probably heard about base themes and sub-themes. Any theme can<br />

declare a parent theme in its .info file using the base theme key and it<br />

will inherit all the hook implementations from its parent theme (and its<br />

parent's parent theme, and so on).<br />

Data granularity<br />

One of the things that makes <strong>Drupal</strong> theming so powerful is its granularity. Each<br />

piece of content is handled separately as it's passed through the theming system.<br />

Each bit of data is themed individually, then combined into ever-larger chunks. At<br />

each step in the aggregation process, it's themed again. The following illustration<br />

will make this clearer:<br />

[ 64 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!