Another indispensable eWorkbook for designers from Emma Jane Hogbin

PHP for Drupal DesignersA couple of weeks ago I reviewed Emma Jane Hogbin's new eWorkbook on Drupal theming. With PHP for Drupal Designers, we are going to have to make that a double: 32 pages with a few examples in PHP for designers, you may ask, what's the big deal? The big deal is that with the info to be found in this condensed form, designers can learn how not to clutter their Drupal templates, developers can learn just what they really need to finally make good on separating coding from layout and styling, and multi-talented groups can learn the Drupal way.

PHP for Drupal DesignersA couple of weeks ago I reviewed Emma Jane Hogbin’s new eWorkbook on Drupal theming. With PHP for Drupal Designers, we are going to have to make that a double: 32 pages with a few examples in PHP for designers, you may ask, what’s the big deal? The big deal is that with the info to be found in this condensed form, designers can learn how not to clutter their Drupal templates, developers can learn just what they really need to finally make good on separating coding from layout and styling, and multi-talented groups can learn the Drupal way.

First designers who are just starting to get their feet wet are sent to brush up on the very basics, using online resources from one of the many “Emma” talks:

• Video: http://www.archive.org/details/FunctionalFipsPHPbasicsforthemers
• Slides: http://www.slideshare.net/emmajane/functional-fips-learning-php-for-drupal-theming

Since this is a hands on workbook, in the very first section it is explained how you can follow along executing the examples by enabling the PHP filter and creating test nodes (on a test site, of course). When you are starting a new language or learning how to program, what you absolutely need is a way to type in stuff and see what happens right away. (Not mentioned: Another alternative would be to install the Devel module and use the “Execute PHP” block which returns its answers in the “info” section just above the content area). Then variables are introduced together with other basics of the language, such as logical operators and conditional statements, and a simple example of how this can be applied to your Drupal theme’s template in some useful fashion.

So what else do you need to know? Well, working with arrays and PHP functions that manipulate arrays, for one thing, as well as “associative arrays” (also known as dictionaries in other programming languages). So that comes next. Then right away, you are given the keys to the kingdom:

<pre>
<?php
$my_vars = get_defined_vars();
print_r($my_vars);
?>
</pre>

Now, the print_r function has long been the mainstay of those trying to figure out what exactly they have to play with under the hood in Drupal. Some very useful snippets you can add to node.tpl.php are provided (print_r($node) for example). Here again, the author does not mention the deluxe convenience of the dsm() function (also provided by the devel module), which replaces the direct print out of huge amounts of PHP arrays and objects with a nice clickable outline in which you can expand and contract elements. Whichever path you choose, right away statements like the following will lose their forbidden mystery:

<?php
print $node>
content['body']['#value'];
?>

Next, PHP functions are introduced with a nice example you can practice with, and this knowledge is immediately applied to Drupal functions, and to making a function of your own, allowing you to print out dates formatted in a variety of ways. In this way the concept of parameters that can be passed to functions is introduced, and then extended.

Then come the last two killer sections, containing well-explained information and tools in a single place that is very difficult to find in an ordered, useful manner.

First of all, in the section entitled Modifying and Creating Theme Variables, you will find yourself downloading and sub-theming a grid-based foundation theme and getting your hands very dirty indeed… so that designers (and you too) don’t have to! All is revealed about how to assign values to variables in the template.php file allowing them to just show up in templates (node.tpl.php, page.tpl.php, etc.). This is the much touted “separation of code and design” in the flesh. And it is explained here so well you will be able to adopt it as part of your best practices, and you, as well as the designers that work with you, will thank you for it!

Cool! Now, what else can drive you crazy as someone just getting started with web design with Drupal? Forms of course! How to alter Drupal’s forms, and actually make them look good!

There are two appendices, one that talks about how to get set up in a development environment (I agree with Emma over text editors vs IDE’s, even though I’ve been using both for decades), and the required reading on version control systems is included. It’s there I have a couple of bones to pick with the author. The difference between the old fashioned and severely limited centralized only model of version control, and its modern, distributed model is clear, and valuable information. However, an uninformed reader could take away the impression of a universe divided into CVS and Bazaar, when in fact for the last decade most centralized model projects have been using SVN, and, in fact, most migrating to the distributed model are adopting Git, rather than Bazaar, including Drupal itself.

But in any case, in such a short workbook, the fact that several pages are devoted to this very important subject is very meritorious.

If you are a designer and have often wondered when you were going to get around to the thorny question of incorporating PHP into your skillset, or if a member of your team is going to be needing to break into that soon, when it is available, grab this eWorkbook up!