Drupal Notes (Retired)

This page is no longer maintained.

My new "Drupal Notes" page can be found here: http://www.group42.ca/drupal

Articles

An article by John VanDyk and Matt Westgate, well known developers in the Drupal community. This article was excerpted from their book Pro Drupal Development.

I've found these especially interesting:

Actual title of the piece is Why Drupal, Joomla, Wordpress and similar software are so popular and 20 things to look for. A nice checklist of considerations when looking at CMSs.

Development / Coding

Command Line Tips & Tricks

"Some quick tips for better productivity when developing Drupal core". Create a command line script to create and review a patch, and apply patches by giving it the Drupal URL.

Hints on searching the Drupal code base from the command line.

From the introduction:

Often times, when you are monitoring the performance of a Drupal site, you need to see what queries are running, and how long they take.

There are several tools to monitor MySQL queries, including mtop and mytop, as well as running SHOW PROCESSLIST from the command line.

However, you sometimes need to filter information from PROCESSLIST's output, such as sleeping threads and such. You also want to see other aspects of the system, for example memory and swapping as well as CPU utilization.

The following simple shell script does that: it displays the process list, filtering out the "noise", as well as display the relevant vmstat line.

Create a shell command so you can CVS check out this way:
drcvs {module} {version}
e.g.: drcvs views 5--1-6

Data Formats

Drupal 5 Data structure of a link

Array
(
    [meetings] => Array
        (
            [title] => Meetings
            [href] => meetings
            [attributes] => Array
                (
                    [rel] => tag
                    [title] => 
                )
        )
)
    

Examples & How To's

There are two ways to do this:

  • Call drupal_get_form('nodetype_node_form'), then use hook_form_alter() to unset the parts you don't need.
  • Create your own form, then do a drupal_execute() using the data from your form.

This article describes how to do both

A nice overview of using Drupal page caching.

Angie Byron describes a "quick and dirty" method for looking at the error message backtrace.

An inventory of the various ways on can change Drupal page text on pages which are not generated directly by users.

A hook menu example.

Concise code examples for creating content types, inserting nodes, and updating nodes.

A quick code snippet for passing the base path into JavaScript:

<span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />&nbsp; $js </span><span style="color: #007700">= </span><span style="color: #DD0000">"var Drupal_base_path = '"</span><span style="color: #007700">. </span><span style="color: #0000BB">base_path</span><span style="color: #007700">() .</span><span style="color: #DD0000">"';"</span><span style="color: #007700">;<br />&nbsp; </span><span style="color: #0000BB">drupal_add_js</span><span style="color: #007700">(</span><span style="color: #0000BB">$js</span><span style="color: #007700">, </span><span style="color: #DD0000">'inline'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span>

Notes in first comment also very useful.

Very good write-up on modifying forms in Drupal 5 and Drupal 6.

Reference

Drupal Handbook: Writing secure code

Information you need to know for writing secure code in Drupal.

Drupal Handbook: Module Developer's Guide

Information on writing modules in Drupal.

Documentation on Drupal system components and a searchable API reference. You'll want to bookmark this one in your browser.

Drupal Handbook: Drupal Coding Standards

Drupal has a coding standard to promote readable code.

A 1 page diagram reference of the various Drupal APIs for Drupal 4.7

A wiki entry with a collection of links useful to people starting in Drupal.

From the introduction, more explanation in the article:

I was browsing around the Devel Module the other day and I noticed a few functions that are not mentioned in any documentation that I've seen but make life even easier, as if Devel doesn't make it easy enough! Almost everyone that's used Devel will be familiar with <strong>dprint</strong>_r (A debug version of the popular print_r function in PHP). Well who has used these ones?

Unit Testing

A really good reference with examples of using the Simpletest module for Drupal unit testing.

A really good overview of the Drupal SimpleTest module and how to use it.

Modules

Access Control

From Angie's introduction:

Most people who use forum systems such as vBulletin or PHPBB are used to having lots of extra features that Drupal core's forums don't contain by default, including private messages, smilies, and BBcode. While all of those are available as contributed modules, there are two "must-have" forum features that are a bit trickier, since they deal with access control: private forums, and forum moderators.

Drupal core tends to have an "all or nothing" approach to these issues. Either a particular role can access all content on the site, or they can access none of it. Either a particular role can administer all forums, or they can administer none of them. Luckily, though, Drupal provides a number of hooks so that contributed modules can add in their own robust access handling.

This article will look at three modules that enhance forum privileges, and compare and contrast them: Forum Access, Taxonomy Access Control, and Taxonomy Access Control Lite.

Content Construction Kit (CCK)

From the introduction:

This article describes the Content Construction Kit, version 5.x-1.4.

The Content Construction Kit (CCK) began as a natural evolution from the popular Flexinode module. The Flexinode module allowed you to define your own content types (a blog entry, a recipe, a poll, etc) with a number of custom fields. CCK also allows you to do this, but in a more powerful way.

Image Handling

Article Introduction:

Suppose you have a site such as an e-commerce site, and you want to upload an image for each product. Suppose further that you have several sizes you want that image to be displayed in, depending on where you are in the site. For example, you might want to have a thumbnail displayed in a product listing, a larger version on the product page itself, and a middle size for displaying in a custom View. And finally, suppose that you'd really rather have Drupal take care of this resizing for you and not have to upload 3+ images for each product you create, so you can spend more time slacking off at work and less time clicking buttons. ;)

There essentially are two different ways to have Drupal do this:

1. Use the Image and Image Exact Sizes modules.

2. Use the imagefield and imagecache modules.

This article will compare and contrast these methods, so you can pick the one most appropriate to your needs (or both!). Read on to find out more!

Article Introduction:

A while ago, Angela Byron of Lullabot wrote an article comparing Image and Image Exact Sizes with CCK Imagefield and Imagcache.

The examples given in the article are clear, but if you are using views, you will need to do some more stuff to get what you want.

Input Filters

A description of how to use the filters provided by Drupal (HTML, Line Break, PHP, URL) and an quick description of other filters that are available.

Management

A blog post by Boris Mann on "cleanly" overriding a core module.

Tracking on Drupal.org

A listing on Drupal.org that advises on new modules.

New Module Listing RSS Feed: http://drupal.org/taxonomy/term/14/0/feed

The RSS feed for the new module listing: http://drupal.org/taxonomy/term/14/0

Operations/Infrastructure

Backup & Restore

Information on backing up your Drupal site.

cron/crontab

A discussion on how to schedule cron jobs as well as a number of references to how to do it on a number of common hosts.

A discussion on using cron on the Dreamhost system. Has a lot of generally applicable information.

Information on the crontab command, including cron entry format information.

Hosting

A discussion of the variable hosting options one might consider.

Monitoring

From the introduction:

Often times, when you are monitoring the performance of a Drupal site, you need to see what queries are running, and how long they take.

There are several tools to monitor MySQL queries, including mtop and mytop, as well as running SHOW PROCESSLIST from the command line.

However, you sometimes need to filter information from PROCESSLIST's output, such as sleeping threads and such. You also want to see other aspects of the system, for example memory and swapping as well as CPU utilization.

The following simple shell script does that: it displays the process list, filtering out the "noise", as well as display the relevant vmstat line.

A discussion of using the command line for monitoring Apache processes and a script, including an explanation of the commands involved (ps, grep, wc). Also includes a script for continuous monitoring and notification when a threshold is exceeded.

Site Configuration

Introduction from the article:

The Apache/PHP/MySQL stack is immensely popular for web application development. Its components are powerful, versatile and Free. Unfortunately however, PHP comes with a default configuration that is not suitable for production mode, and may cause developers to use insecure techniques during the development phase. Inside is a check list of settings that are intended to harden the default PHP installation.

This article describes how to limit access to update.php by adding an access rule to the Drupal .htaccess file.

Theming

An assortment of technical fiddly-bits on working with the PHPTemplate theme engine. Mostly 4.7 information, some of the theming techniques like a separate admin theme have been replaced with settings in Drupal 5.

From the article introduction:

An often requested feature for sections module (or Theming in general) is to be able to style nodes with certain terms (and therefore forums) different.

Off course you can build a module for this, with a nice interface an all that. And off course you can do this with sections module. But both are quite over the top, for such a simple tasks; Worse: such modules will be big, but will never be able to cover all the cases and questions. A few lines of PHP in your theme is all you need. and PHP is as flexible as you want it to be.

This small howto will help you create some template code to add classes to your nodes, based on wether or not they contain certain terms. It will check for terms in a certain vocabulary only.

Drupal Handbook: Regions in PHPTemplate

Drupal handbook documentation on creating new regions in PHPTemplate.

An inventory of the various ways on can change Drupal page text on pages which are not generated directly by users.

A example of how to use the theming system to add extra information to the Drupal menu HTML so CSS can be used to add images.

For your templating pleasure Drupal's PHPTemplate engine makes available a cast of variables, including such favourites as $title, $content, and $node. Modules also contribute: CCK adds CCK specific template variables as well as fields to the node object, and the comments module adds an entry to the $links variable. But what happens when something isn't formatted the way you or your customer wants, or you have a project specific variable you want to add?

Theme Variable Total Visibility (Finding Variables available in your theme)

Need to know absolutely, positively, and without-a-doubt what theming variables are available to your template? Here's a trick for total visibility.