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 />

As you can see in the preceding illustration, for a typical blog post, each comment<br />

is pulled from the database and sent through the theme system to get HTML<br />

markup added to it. Then all the comments are aggregated together into a "comment<br />

wrapper" where additional markup and, usually, a "new comment" form is added.<br />

Then the single group of comments is passed to the node theming where it is<br />

combined with other pieces of the blog post's content. This process of theming bits<br />

of content, aggregation, and theming again is repeated until we've built the entire<br />

HTML page ready to be sent to a web browser.<br />

There are two advantages to this granular system. First, since each module is<br />

responsible for theming its own data, it can either create a very specialized theme<br />

hook for its data or it can re-use an existing theme hook. Re-using a theme hook<br />

ensures a consistent set of markup for similar data structures while still allowing<br />

customized CSS classes (Most theme hooks allow custom classes to be passed<br />

as parameters.) For example, the list of links after a node (read more, add new<br />

comment, and so on) re-uses the links theme hook, and the links after each<br />

comment use the same links theme hook.<br />

The second advantage is for the theme developer. Having a fine-grained theming<br />

system means that a theme, if it chooses to, can literally rewrite all of the markup for<br />

its own design purposes. As module developers we need to be keenly aware of the<br />

themer's desire to have granular theming overrides.<br />

[ 65 ]

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

Saved successfully!

Ooh no, something went wrong!