18.10.2016 Views

Drupal 7 Module Development

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 3<br />

to simply implement a spook_preprocess_page() function, it would be run after<br />

template_preprocess_page() and, thus, too late. So, instead we need to implement<br />

the following code:<br />

/**<br />

* Implements hook_theme_registry_alter().<br />

*/<br />

function spook_theme_registry_alter(&$theme_registry) {<br />

// Add our custom preprocess function to the beginning of<br />

// the preprocess function list.<br />

array_unshift($theme_registry['page']['preprocess functions'],<br />

'spook_control_page_messages');<br />

}<br />

/**<br />

* Implements a custom preprocess function; one that is not<br />

* auto-discovered during the theme registry build.<br />

*/<br />

function spook_control_page_messages(&variables) {<br />

// Override #show_messages before template_preprocess_page()<br />

// accesses it.<br />

$variables['page']['#show_messages'] = spook_get_control();<br />

}<br />

The order of preprocess functions described in the earlier section is created during<br />

the theme's system registry build and is based on the naming conventions. However,<br />

hook_theme_registry_alter() allows us to alter that ordering to suit our own<br />

nefarious purposes.<br />

What else?<br />

For most modules you write, the contents of this chapter cover everything you<br />

need to learn about the theme system. Actually, this chapter might have been TMI.<br />

However, the theme system is chock full of yummy goodness not covered here,<br />

including accessibility classes, hook_theme_enable, and hook_theme_disable to<br />

name just a few. <strong>Drupal</strong>'s online documentation includes a theme reference guide<br />

which can be a very handy tool for understanding some of the more obscure topics.<br />

It can be found at the following site:<br />

http://drupal.org/theme-guide<br />

[ 89 ]

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

Saved successfully!

Ooh no, something went wrong!