Learning Drupal 6 Module Development

This book review was published by Slashdot, .

Learning Drupal 6 Module Development

Of all the content management systems (CMSs) that a Web developer could use for creating a new site, the best ones allow the developer to extend the chosen CMS's capabilities, by adding new functionality, in the form of third-party modules. This is one of many reasons why Drupal is growing in popularity: Developers can choose from hundreds of Drupal modules. But not all functionality that a developer might want has been captured in a module, and many of the modules are unfinished or otherwise limited in capabilities. Fortunately, PHP programmers can create their own modules, and one way to get up to speed is Learning Drupal 6 Module Development, authored by Matt Butcher.

Published on 10 May 2008 by Packt Publishing, under the ISBN 978-1847194442, the book is intended as a tutorial for developing your first Drupal 6 module; yet it also explains how to create themes and custom content types, how to use external XML APIs, and how to add AJAX functionality to your Drupal site using jQuery.

The book spans 328 pages, grouped into nine chapters, each devoted to a major topic of Drupal module development: Drupal's architecture and primary concepts (nodes, users, blocks, menus, etc.); an introduction to building a new module; Drupal's theme system, and how to create a custom one; module theming; using JavaScript, AJAX, and JSON; creating a custom administration module; creating a new content type, using the CCK; filters, input formats, hooks, actions, and triggers; installation profiles, how to develop one, and how to package a distribution. Throughout the book, the author illustrates key ideas by applying them to a sample website, named the Philosopher Bios. The material assumes that the reader has a solid understanding of the essentials of PHP and SQL, and familiarity with Drupal's administration area. But no advanced PHP or MySQL knowledge is required, nor prior experience creating Drupal modules and themes.

Packt Publishing has made available a Web page for the book, where visitors can order the book (print and electronic copies), download the book's sample code, provide feedback to the publisher, send in a question, read a summary of the book or the table of contents, and obtain a sample chapter (Chapter 2 — "Creating Our First Module"). One would expect to find a link to errata reported for this specific book, but this page does not have such a link. In fact, none of the book profile pages on Packt Publishing's site appear to have links to their respective errata. Instead, the visitor must go to their support page, specify the book of interest (the drop-down list should default to the last book review, but it does not), and finally click on the errata link, which should have been on the individual book's page. After clicking a link, a small and non-resizable browser window pops up, listing the known errata.

To Web developers unversed in Drupal's architecture and the use of modules to extend Drupal's core capabilities, the first chapter of this book should be quite valuable, because the author explains how Drupal's functionality has been logically organized into modules. For developers unfamiliar with CMS modules, the author sums it up nicely: "A module is a bundle of PHP code and supporting files that use Drupal's APIs and architecture to integrate new functional components into the Drupal framework." As noted earlier, the author presents overviews of the most critical Drupal concepts, including core modules, hooks, themes, nodes, comments, users, blocks, page rendering, menus, and forms. Unlike what is found in far too many programming books, the explanations in this chapter are generally quite complete, authoritative, and clear — with the exception of the last note on page 8 pertaining to system modules. The chapter concludes with a brief discussion of the demonstration site created in the book, as well as some developer tools recommended by the author.

In the second chapter, readers learn the basics of creating a module — in this case, one that accesses a philosophy reading list from Goodreads. Anyone who does not yet own a copy of the book, can quickly see the overall style of the book's information and presentation, by downloading the aforementioned sample chapter. There are few blemishes in this chapter: A short (and apparently non-facetious) phrase in one of the notes, "Drupal is meticulously documented..." (page 30), should come as a surprise to anyone who has stumbled into one of the gaps in Drupal's online documentation. The reader should beware that the code for the two private functions used in the sample module, differs between the book's code and that in the download archive, with no indication to the reader from either source as to which is to be preferred, if any. The book's code has other problems, as described in the errata. Also, tags such as "<channel/>" and "<item/>" may give the reader a false impression that those are empty tags (i.e., single tags, and not paired open/close tags). Unfortunately, this nonstandard and confusing notation is used throughout the book.

Theming a website is an important part of making it attractive and more usable to site visitors, and Drupal, like any solid CMS, has built-in support for applying themes to a site. In the third chapter, the author explores Drupal's theme system and theme engines, as well as how to create a new theme, and how to use Drupal's hook system for overriding a template function. The discussion is better than that seen in any other book, but could be further strengthened if the author were to explain the reasoning behind some of the suggested practices, such as making redundant copies of a parent theme's images for a sub-theme. Any readers implementing the "descartes" sub-theme should note that template.php, in the download code, begins with "<?" and not "<?php", which will cause problems if their PHP has short_open_tag set to Off. Chapter 5 extends the ideas presented earlier, and shows the reader how to create a new module with a default theme. The discussion of how to register a theme and, more specifically, the naming conventions, is in some places rather turgid — not due only to the writing, but partly Drupal's overriding scheme. But it does not help to have array keys such as "theme_function_name" mentioned in the text but not in the code (should it be "<theme function name>", following his earlier naming convention?). Partway through the fourth chapter, the author acknowledges that the reader may be getting lost in the terminology, and clarifies it. This is a worthy practice that could have been employed in several other places in the book (and by the authors of other programming books).

In the fifth chapter, readers will find a detailed discussion of how to leverage the power of AJAX, jQuery, and JSON to allow modules to refresh with changed content, without requiring Drupal to reload the entire Web page. Chapter 6 explains how to create a module with an administration interface, as well as how to use the powerful Forms API (FAPI), and the Mail API, among other Drupal capabilities available to the programmer. Creating a nontrivial content type that incorporate specialized fields, is the subject of Chapter 7. It is accomplished by building a new module, rather than the more common approach of using the Content Construction Kit (CCK). Readers will also benefit from an introduction to the Schema API, which is valuable for generating database-neutral SQL code. In Chapter 8, the author explains how to create content filters, actions, and hooks, as well as how to assign a trigger to an action. Like the previous two chapters, this one is fairly long and takes some work to fully digest, but doing so is essential for learning how to make the most of hooks, among the other topics. The author also shows how to indicate that your new module depends upon others. The final chapter covers installation profiles and packages, which allow the developer to put together a customized version of Drupal containing the new modules he or she has created, in addition to any dependent non-core modules.

Overall, Learning Drupal 6 Module Development accomplishes its primary goals, and provides information that would even be of interest to Drupal developers who may have no intention of ever creating their own modules and themes, but who would like to learn a lot more about Drupal's underlying architecture, and some of the differences between versions 5 and 6. The author tackled a difficult subject area, and presents enough explanations that would allow any experienced PHP programmer to work through the examples and learn from them. There are plenty of screenshots and diagrams, all of which are helpful. However, a few of the screenshots are intended to show color changes, which makes no sense because all of the screenshots are grayscale only. Rather than choosing orange and pink and other colors, distinct shades of gray would probably have been a better approach.

The book's remaining flaws — aside from those noted above — are relatively minor. The chapter summaries are of no value, and could be dropped in the interests of making the book leaner. Some of the paragraphs are overly short, and should be combined with adjacent ones (e.g., "Here is one very good reason."; page 111). Some of the phrasing is weak (e.g., "has got better and better"; page 18), confusing (e.g., "a typical template work"; page 60), or incorrect (e.g., "uninspiring"; should read "uninspired"; page 70). Other similar problems are identified in the book's errata. The author misses many opportunities to use commas to improve the text's readability, and even uses them incorrectly with parentheses (page 64). Some proper names do not have correct title case, such as "Windows explorer" (page 35). Throughout the manuscript, "hookname" should instead read "hook name". The possessive term "its" should contain no apostrophe (page 185, for example). Occasionally, a (non-critical) word is missing, such as in "content is main content" (page 33). Yet in none of these instances should the alert reader be unable to determine what the author is stating.

None of the weaknesses identified above detract from the overall value of the book. As of this writing, Learning Drupal 6 Module Development is the most promising and information-rich resource for Drupal developers interested in creating their own modules and themes.

Copyright © 2008 Michael J. Ross. All rights reserved.
bad bots block