What is Drupal?

Drupal is an open source content management platform that allows non-technical people to easily manage, update, and create new content for their web site.

Known for its modular architecture and ability to scale well for large web sites, Drupal offers the following benefits over competing content management systems:

  • Open-source development model
    • No licensing fees
    • No vendor lock-in
    • Large developer community (easy to find Drupal talent)
    • Thousands of contributed modules (less custom code to write, less expensive to customize)
  • Powerful feature set
    • Blogs, comments, forums, and polls
    • Custom content types: create new content types (photo gallery, book reviews, etc) through a web-based interface
    • Taxonomy system for categorizing content
    • User registration, profiles, and role-based permissions
    • Access statistics and event logging
    • Advanced site search capabilities
    • SEO-friendly URLs
    • Multiple-level menu system
    • Multiple-site support
    • Multiple-user content creation and editing
    • OpenID support
    • RSS Feed and Feed Aggregator
    • Security and new release update notification system
    • Workflow tools (Triggers and Actions)
  • Extensibility
    • More than a CMS: also used as an application framework
    • Clean, modular, and well-documented code base
  • Performance
    • Caching and feature throttling for improved performance in high-traffic environments
    • Proven performance on high-profile sites such as whitehouse.gov, theonion.com, fastcompany.com, popsci.com, and more.

Useful Drupal Modules to Jump-Start Your Web Development

404 Blocks

On 404 pages, Drupal (by default) doesn’t render “left”/”right” regions of your theme nor menu blocks.

The 404 Blocks menu revives these blocks on 404 pages so that your visitors have navigation options when they hit a page not found.

Admin Menu

While Drupal’s “navigation” menu is suitable for content editors and authenticated users with limited permissions on your Drupal site, a common problem site administrators face is the endless clicking through nested lists to manage their site configuration. The Admin Menu module provides a superb solution to this problem. Admin Menu adds a small drop-down menu at the top of your Drupal site with an efficient, intuitive structure for navigating Drupal administration pages and functionality.

Screenshot:

Admin Role

The Admin Role module is a nifty utility for creating and maintaining a Drupal administrator role to which you can assign your users. Admin Role will relieve you of the burden of keeping track of and assigning new permissions to your users every time you add a new module to your Drupal installation.

Auto Assign Role

The Auto Assign Role module is helpful for Drupal sites that allow registration for different roles. The module allows new users to select the role they want to be assigned during registration. In addition, you can provide a unique path to your registration form such that anyone who registers at that path automatically receives a given role.

The Auto Assign Role module can help you automate the process of role assignment rather than manually selecting new users’ roles after registration.

Backup and Migrate

The Backup and Migrate module is a must-have for backing up your Drupal data and/or migrating your database from one installation to another. The Backup and Migrate module provides an automated backup schedule, compression of backup files, and optional exclusion of selected tables in the Drupal database (such as cache tables).

Screenshot:

Boost

The Boost module provides advanced caching functionality beyond Drupal’s standard block and page caching. Its static page caching method is meant primarily for sites that receive primarily anonymous traffic. Boost will cache and compress (with gzip) your html, xml, ajax, css, and javascript files, with configurable, granular cache lifetimes. Boost’s authors recommend the module as the best option for improving performance in shared hosting environments.

Drush

Drush (short for Drupal Shell), is a command line interface for Drupal. The Drush module allows administrators to perform many common Drupal tasks through the command line, which cuts down on the time required to navigate the web-based Drupal admin interface.

Drush stands out among the thousands of Drupal modules as a very effective way to boost your productivity, especially for downloading and installing modules during your initial setup and performing other tasks in your development environment.

Some of the more common commands for Drush (version 3.x) include:

  • Download modules and themes to your Drupal sites directory
    $ drush pm-download views cck zen
  • Enable modules and themes
    $ drush pm-enable views cck zen
  • Disable modules and themes
    $ drush pm-enable views cck zen
  • List available modules and themes
    $ drush pm-list
  • List enabled/disabled modules
    $ drush pm-list --type=module --status=enabled
  • List disabled modules
    $ drush pm-list --type=module --status=disabled
  • Run cron
    $ drush cron
  • Update active modules and themes
    $ drush pm-update
  • View the update status of active modules and themes
     $ drush -n pm-update
  • Run update.php
     $ drush updatedb
  • Clear Drupal’s cache
    $ drush cache-clear

Screenshot:

Global Redirect

The Global Redirect module helps prevent Drupal from displaying the same content across multiple URL’s. This can happen when you’re using clean URL’s, because (by default) Drupal does not remove the old path (e.g. /node/1) after you’ve set the clean url (e.g. /home). Further, Global Redirect corrects many more aliasing problems encountered such as removal of trailing slashes, 301 redirects on stale aliases, and others.

Less

The Less module (along with the bundled lessphp library) allows you to write LESS files as a replacement or substitute for CSS. If you’re unfamiliar with LESS, check out less.org

After creating your LESS stylesheet, simply include it in your .tpl file:

drupal_add_css('filename.less')

or in your theme’s .info file:

stylesheets[all] = filename.less

Menu Settings for Content Type

The Menu Settings for Content Type module (one of the lesser known/used modules for Drupal) provides a simple way to limit menu selections based on the node’s content type.

Of course, Drupal allows us to set the “Default Menu for Content” at /admin/build/menu/settings. However, this setting merely pre-populates the menu “Parent item” drop down with the default menu that you choose.

If you’re building a site with several menus, or if your menus have a large number of items, it can be confusing for your users to digest the long list of menu items presented in the node’s “Parent item” drop down.

Hence, the Menu Settings for Content Type module provides a checkbox on your content type editing screen to “Enable the Menus you want to be available for this Content Type”. Restricting this option to one menu will prevent other menu items from appearing in the “Parent item” drop down for all nodes of that type.

Screenshot:

Node Form Settings

The Node Form Settings module provides custom configuration of node and comment forms. Some of it’s more useful options includ

  • Remove the “Split summary at cursor” checkbox
  • Remove the “Input Format” fieldset
  • Change the default text on the Submit button
  • Remove the preview button
  • Remove the node title
  • Remove revision log field
  • Show a ‘Cancel’ link on node edit form.

Once you’ve installed the module, you must configure the Node Form Settings for each content type you’d like to alter.

Screenshot:

Poormanscron

Newer Drupal administrators who haven’t setup cron on their server nor installed Poormanscron will often be puzzled over Drupal status messages along the lines of:

Drupal core update status
No update data available. No information is available about potential new releases for currently installed modules and themes. To check for updates, you may need to run cron or you can check manually. Please note that checking for available updates can take a long time, so please be patient.

Not knowing what cron is or how to automate it, many administrators will simply click the link to run cron manually and rid themselves of these messages.

Cron is the script that performs Drupal maintenance tasks, such as clearing out old log entries, scheduling email, updating the search index, and other tasks that require frequent updates.

Traditionally, Drupal administrators had to configure their web server to run Drupal’s cron.php script by editing the crontab file on the server. By specifying the interval in crontab, the server knows when to run Drupal’s cron.php script and perform regular Drupal updates.

However, some shared hosting plans don’t provide easy access to crontab, and setting cron on your server is considered to be a bit of a pain.

The Poormanscron module allows Drupal administrators to skip cron configuration and avoid the need to run cron manually in order to keep Drupal up-to-date. Poormanscron triggers the automatic running of the cron.php script based on triggers activated by normal visits to your site.

The Poormanscron module is available for Drupal 6 and older, and its functionality will be integrated directly into Drupal 7.

Prepopulate

The Prepopulate module allows you to pre-fill Drupal forms with $_GET variable

This allows you to craft URLs in a manner that pre-populates Drupal forms, such as when you’re creating a new page or other content type. Pre-populating forms comes in useful when you want to create content in batches, or for creating bookmarklets to speed up the creation of blog posts.

An example pre-filled URL might look like this:

http://www.example.com/node/add/page?edit[title]=this%20is%20the%20title&edit[body]=body%20goes%20here

Remember, special characters need to be encoded for URLs in order to ensure consistent behavior. If you’re running a large batch of form pre-populations, it’s a good idea to write a simple PHP script to encode your content and auto-generate the corresponding links for the Prepopulate module.

Security Review

The Security Review module performs automated checks for security vulnerabilities due to Drupal configuration errors.

Skinr

The Skinr modules allows you to control various theme styles through Drupal’s user interface.

Trigger

The Trigger module, which ships with Drupal core, allows administrators to trigger configured actions in response to Drupal system events, such as account creation, comment creation, node creation/editing, et

Actions can be as simple as sending an email to an administrator or unpublishing comments that contain profanities. Other modules can also expose their own events to Drupal’s Trigger module so that administrators can attach actions to custom events.

Vertical Tabs

The Vertical Tabs module provides a really nice improvement to the Drupal 6 user interface. Vertical Tabs replaces Drupal’s default expandable form fieldsets into a vertically-stacked set of tabs for each fieldset. The result is enhanced usability and a more effective use of screen real-estate for Drupal’s forms. See the attached screenshots for a comparison of Drupal default fieldsets and fieldsets enhanced with the Vertical Tabs module.

Screenshot:
Drupal 6 form fieldsets enhanced with Vertical Tabs
Drupal 6 default form fieldsets

Drupal Development Tips

Remove the Link to a User’s Blog on Drupal Blog Entries

By default, Drupal provides a link to the user’s blog on each of the posts authored by the given user. To remove this link from your template, place the following code in your template.php file (located in your theme directory):

function phptemplate_links($links, $attributes = array()) {
unset($links['blog_usernames_blog']);
return theme_links($links, $attributes);
}

Validating PHP Files in your Project

If you’re working on a PHP project and making changes to multiple files, it’s often helpful to check for syntax errors as you’re working. One method to perform this check is to run the PHP script on your local web server.

However, another method that’s particularly useful for large sets of PHP files is to execute the files recursively at the command prompt. To accomplish this, run the following command at the prompt after navigating to your project directory:

find . -type f -name \*.php -exec php -l {} \;

Of course, typing this out (much less remembering it) is a serious pain, so be sure to stuff this away in your

.bash_profile

file:

alias validate_php_files="find . -type f -name \*.php -exec php -l {} \;"

With this command-line alias configured, you can now run the following at the command prompt:

cd ~/path/to/my/php/project
validate_php_files

Which will give you output similar to:

No syntax errors detected in ./_masters/phpinfo.php
No syntax errors detected in ./_masters/tests/FunctionsTest.php
No syntax errors detected in ./_masters/tests/LoopTest.php
No syntax errors detected in ./admin/index.php
No syntax errors detected in ./includes/class.args.php
No syntax errors detected in ./includes/class.auth.php
No syntax errors detected in ./includes/class.config.php
No syntax errors detected in ./includes/class.database.php
No syntax errors detected in ./includes/class.dbobject.php
No syntax errors detected in ./includes/class.dbsession.php
No syntax errors detected in ./includes/class.error.php
No syntax errors detected in ./includes/class.gd.php
No syntax errors detected in ./includes/class.loop.php
No syntax errors detected in ./includes/class.objects.php
No syntax errors detected in ./includes/class.ormobject.php
No syntax errors detected in ./includes/class.pagepref.php
No syntax errors detected in ./includes/class.pager.php
No syntax errors detected in ./includes/class.rss.php
No syntax errors detected in ./includes/class.stats.php
No syntax errors detected in ./includes/class.tag.php
No syntax errors detected in ./includes/functions.inc.php
No syntax errors detected in ./includes/master.inc.php
No syntax errors detected in ./login.php
No syntax errors detected in ./logout.php

Drupal Launch Checklist

This is a simple collection of tasks that comes in handy when pushing your Drupal site from your development environment to production. It is by no means comprehensive, and, depending on your site configuration and the modules you’ve installed, your launch checklist may vary.

Backups

  • Install Backup and Migrate and setup a regular backup schedule for your database dumps. Alternately, create your own backup script and use cron to run it on a regular basis.

Files

  • Ensure your server’s temp directory is writable at admin/settings/file-system

Users

  • Configure your user registration guidelines and email templates
    /admin/user/settings
  • Remove any guest or temporary accounts you setup during development

Modules

  • Disable any modules that your site isn’t using
  • Disable developer modules, such as cache_disable, coder, content_copy, debug, delete_all, demo, devel, devel_node_access, devel_themer, macro, form_controller, imagecache_ui, journal, trace, upgrade_status, user_display_ui, util, views_ui, views_theme_wizard

Reporting

  • Set your custom “page not found” (404) and “access denied” (403) pages, if desired
    /admin/settings/error-reporting
  • Turn off error reporting display
    /admin/settings/error-reporting
    (select “Write errors to the log” under the drop-down titled “Error reporting”
  • Check your Status Report to be sure your Drupal installation, modules, and themes are up-to-date
    /admin/reports/status
  • Ensure you’ve configured Drupal to check for available updates and alert your via email when updates are available.
    /admin/reports/updates/settings

Security

  • In your production environment, install the Security Review module, run its automated tests, and make appropriate adjustments.
  • Double-check your permissions at admin/user/permissions

Views

  • Ensure you’ve added the Node: Published filter to all public-facing views
  • Analyze your views for warnings or hefty MySQL queries

Caching

  • Enable your site’s caching mechanisms, such as Page Cache, Block Cache, and bandwidth optimizations for JavaScript and CSS files
    /admin/settings/performance
  • Consider installing the Boost module

Other

  • Consider installing the Global Redirect module in order to prevent the representation of the same content over multiple URL’s, which can result in search engine sandboxing
  • If you’re using the IMCE module, adjust the quota limit (which defaults to 2 mb) for the space a user may take up on the server
  • Setup cron on your web server, or install the Poormanscron module
  • Activate the Drupal core Trigger module and configure it to work with actions so that you can be notified when users register, post new content, add comments, and other events. If you have comments set to be automatically published without approval, it’s also a good idea to create an action to automatically unpublish comments with profanities in them.
  • Configure your JPEG quality settings for Image API (admin/settings/imageapi) and Drupal’s image tookkit (admin/setings/image-toolkit)

Change the Default Button Text for Exposed Filters

By default, Drupal sets the text for the Exposed View button to “Apply”, which isn’t very intuitive to the end user.

In order to change the default text for this button to something more intuitive, open up your theme’s template.php file (or create it if it doesn’t exist) and add the following:

<?php
function theme_name_preprocess_views_exposed_form(&$vars, $hook) {
$vars['form']['submit']['#value'] = t('Search');
unset($vars['form']['submit']['#printed']);
$vars['button'] = drupal_render($vars['form']['submit']);  
}
?>

Where

theme_name

is the name of your theme.

As a result, the default “Apply” text will be replaced with the more intuitive “Search” text, or any text of your choosing.

How to Properly Install a Drupal Module

Installing a Drupal module can be a daunting task for beginners, but the process is fairly painless once you’ve done it a few times. This article walks you through the process of installing one of the most popular modules (#6 at the time of writing): Administration menu.

Download the Module

The first step to installing your Drupal module is to locate its Project Page on the Drupal.org site. You can accomplish this in multiple ways:

  • Search for “Drupal [module name]” in your preferred search engine
  • Go to Drupal.org and enter the module name in the search box in the top right. If you have several search results and your not sure which one to choose, you can click “Project” under the “Filter by type” heading on the right. This will ensure your search results are limited to active Drupal projects (which are usually modules).
  • If you know the machine-readable name of the module, you can simply type http://drupal.org/project/module_name in your browser’s address bar, where “module_name” is the machine readable name of the module you want to install.

Once you’ve found the project page for the Administration menu module, be sure to read the author’s notes. In addition to providing a basic overview of the module and suggested usage, the author often provides helpful links to complimentary modules or other modules that provide similar functionality.

After the author’s notes, you’ll see a section titled “Downloads”. You’ll want to download the modules highlighted in green, which represent the author’s recommended downloads which have been tested to work properly for various versions of Drupal.

You’ll notice that, sometimes, there are multiple recommended versions of the module, each prefixed with 6.x, 5.x, etc. These numbers correspond to the version of Drupal each of the module releases is compatible with. If you’re running Drupal 6, you want to download the module prefixed with 6.x.

Click the “Download” link next to the appropriate module version for your Drupal installation, and save it to your hard-drive.

Extract the Module

By default, Drupal modules downloaded from Drupal.org have been compressed into a “tar archive” file. As a result, the module you downloaded will be named filename.tar.gz. This compressed file is similar to a “zip” archive (files named filename.zip) that you might be familiar with.

To extract the tar archive on a Mac, simply double-click the tar.gz file, and it will be extracted using Mac’s Archive Utility. You will see a new folder that should be named admin_menu (notice that this is the machine-readable name referenced in the project URL on Drupal.org.

Place the Module in your Sites Folder

If you are running Drupal on a local web server, move the admin_menu folder to the following location:

DRUPAL_ROOT/sites/all/modules

If you’re running Drupal on your web hosting provider’s server, upload the module to the DRUAPL_ROOT/sites/all/modules folder using your FTP client.

Where DRUPAL_ROOT corresponds to the main folder of your Drupal installation. If you do not see a folder named modules inside the sites/all folder, create it.

Note: there is a “modules” folder inside your Drupal root folder. However, do not place your module here, because this modules folder is reserved for core Drupal modules, not the modules you’ve downloaded from Drupal.org.

Enable the Module

Once you have moved your module into the sites/all/modules folder, you’re ready to activate it using Drupal’s administration interface.

Go to admin/build/module/list and locate the Administration Menu module (it should be listed near the top). Click the checkbox beneath the “Enabled” column heading, then scroll to the bottom of the page and click the “Save Configuration” button.

That’s it! You should now see the activated Administration Menu at the top of your Drupal administration pages.

Show Available PHPTemplate Variables

During theme development, it’s often helpful to show a list of available PHPTemplate variables that are provided by Drupal core and any modules you’ve installed. One way to do this is to install the Theme Developer module. Another is to place the following code at the top of your page.tpl.php file:

Print the variables array

<?php
print '<pre>';
print_r(get_defined_vars());
print '</pre>';
?>

Print the variables array with HTML markup

<?php
print '<pre>';
print htmlspecialchars(print_r(get_defined_vars(), TRUE), ENT_QUOTES);
print '</pre>';
?>

Source: Drupal.org

Template Files

To override a particular template file, copy the appropriate file below and paste it into your theme directory.

  • modules/node/node.tpl.php
  • modules/system/page.tpl.php
  • modules/system/block.tpl.php
  • modules/system/maintenance-page.tpl.php
  • modules/comment/comment.tpl.php
  • modules/comment/comment-*.tpl.php
  • modules/forum/forums.tpl.php
  • modules/forum/forum-*.tpl.php

For custom content types, create the following file in your theme directory:

  • node-nodetype.tpl.php

where nodetype is page, story, forum, blog, or the machine-readable name of any of your custom content types.

Additional template files include:

  • page-front.tpl.php

    (which only affects the layout of the homepage)

Additional template files and their locations can be found at Drupal.org

Defining Features in Your Drupal Theme

In Drupal themes, features are the parts of a theme that can be toggled on or off in the theme administration page (/admin/build/themes) under the “configure” tab.

Drupal has several default features, which can be overridden

In your theme’s .info file, you may or may not see features declared. If features are not declared within the .info file, the default features provided by Drupal are available. However, if your .info file declares other features, Drupal will no longer use the default features, so it is up to you to re-declare them alongside your custom features (or leave them out if you don’t want to use them).

features[] = logo
features[] = name
features[] = slogan
features[] = mission
features[] = node_user_picture
features[] = comment_user_picture
features[] = search
features[] = favicon
features[] = primary_links
features[] = secondary_links

Defining Regions in Your Drupal Theme

In Drupal themes, regions are the areas that contain blocks. If you head over to your block configuration page (/admin/build/block) with the Garland theme enabled, you’ll notice the following five regions on the page (indicated with dashed outlines):

  • Header
  • Left sidebar
  • Right sidebar
  • Content
  • Footer

These are Drupal’s five default regions, available to all themes.

In your theme’s .info file, you may or may not see regions declared. If regions are not declared within the .info file, the five default regions provided by Drupal are available. However, if your .info file declares other regions, Drupal will no longer use the default regions, so it is up to you to re-declare them alongside your custom regions (or leave them out if you don’t want to use them).

For example, the following region definitions in your .info file will add a “banner” region and maintain Drupals five default regions:

regions[banner] = Banner
regions[header] = Header
regions[left] = Left sidebar
regions[right] = Right sidebar
regions[content] = Content
regions[header] = Footer

Note: Drupal 7 adds the following default region:

regions[help] = Help

Once you’ve defined the regions in your .info file, you’ll need to add them in your theme’s

page.tpl.php

file. For example, you might add

<?php print $banner; ?>

to correspond to the banner region. Note that you’ll also need to edit your theme’s CSS file to add whatever styling you see fit for the new region (for example, width, height, background, or bordering).

Theme .info File

Your theme’s .info file defines the theme’s capabilities and other information such as its name, description, Drupal version compatibility, and the theme engine it utilizes. In addition, the .info file can define the block regions available to the theme, as well as external files (CSS and JavaScript) the theme uses.

If we open up the .info file for the Garland theme (which ships with Drupal core), we see something like this:

name = Garland
description = Tableless, recolorable, multi-column, fluid width theme (default). 
version = VERSION 
core = 6.x 
engine = phptemplate 
stylesheets[all][] = style.css 
stylesheets[print][] = print.css

Oftentimes, when you’re using a contributed theme, it’s helpful to extend the theme with your own CSS files and/or JavaScript. Rather than editing the individual CSS and JavaScript files that ship with the contributed theme, you can edit the theme’s .info file to add custom CSS and JavaScript files to load.

To make it easier to maintain compatibility with future releases of the contributed theme you’re using, you might add the following to your theme’s .info file like this:

stylesheets[all][] = custom/css/custom.css 
scripts[] = custom/js/custom.js

Be sure to add these lines after any existing stylesheet or script declarations, so that your CSS rules override the theme’s default rules.

Next. you can add the directory named “custom” to your theme’s directory and create the associated CSS and JavaScript directories and files. When the contributed theme you’re using has available updates, be sure to maintain your custom directory and re-edit your theme’s .info file to integrate any updates while maintaining the declarations for your custom CSS and JavaScript files.

Let’s Talk!

Schedule a call, send a note, or request a quote for your next project.


Get Started

  • Drop files here or
  • This field is for validation purposes and should be left unchanged.