Last updated November 30, 2012. Created by LeeHunter on September 27, 2007.
Edited by Elijah Lynn, pfrenssen, jwolf, peterx. Log in to edit this page.

The devel module is an invaluable tool for constructing and coding websites. It has many features, such as dprint_r(), dpm(), a clear_cache button, and a generate_random_nodes feature. Devel is usually used for low-level development of a site, while the also-loved Util.module handles site-wide administrative features that are cool, and just don't exist in core for one reason or another.

What does dprint_r() do?

The dprint_r function is a really cool tool for peeking inside of a Drupal array to see what's there. It "pretty-prints" the array into a human readable paragraph, rather than just spewing all the variables out onto the page one after the other in an endless and mostly incomprehensible strand like PHP's print_r() function would do. There are several ways to implement it, and all of them require the devel module in order to work.

// Example of an array viewed with Devel's dprint_r()
Array
(
    [form] => Array
        (
            [568717fb5880cf349c074f20f92ef326] => Array
                (
                    [timestamp] => 1189457316
                    [args] => Array
                        (
                            [0] => system_modules
                        )
                )

// Example of an array viewed with PHP's print_r()
Array ( [form] => Array ( [568717fb5880cf349c074f20f92ef326] => Array ( [timestamp] => 1189457316 [args] => Array ( [0] => system_modules ) )

Which one is easier to read? Now you know why you want to use this snippet, so let's get to it!

Example 1 - printing an array from within a custom module

Here's the code snippet:

if (module_exists('devel')) {
  dprint_r($_SESSION);
}

It's important to know that sometimes, depending on where your particular module falls in the core's own build process, you might be able to generate a fatal error by trying to call dprint_r() from inside your own module. Even if devel exists, it might not be fully rendered as a set of php functions yet. If this happens to you, simply move this code snippet inside one of your module's functions rather than leaving it naked at the top of your module, and the error will stop.

Other array variables you can use:
The $_SESSION array is just one example. You could use dprint_r($GLOBALS) to see all global variables in use at that moment, or dprint_r($_POST) to show the last form submission's $post array, or even dprint_r($_COOKIE) if you needed to find out what the user's cookies were storing for you at that moment in time.

Example #2 - Printing an array directly into a theme's output

Place this into your node.tpl.php to show the contents of the first node. Replace the "1" with any number of your choice, as long as it's a node that exists in your site.

<?php
if (module_exists('devel')) {
 
$node = node_load(1);
  
// Show what's in node 1
 
dprint_r($node);
}
?>

Controlling placement on the page:
You can generate the printed array into a block, into a footer, or into a $messages box, like the "login successful" message that Drupal prints out automatically when a user logs in.
To print in a block, see http://api.drupal.org/api/function/hook_block/5, footer, see http://api.drupal.org/api/function/hook_footer/5, and $messages, see http://api.drupal.org/api/function/drupal_set_message/5

How can dpm() help me?

The dpm() function prints any variable directly into the drupal $messages box on your page. The $messages box is that specially-colored area in your theme that Drupal uses to announce cool events such as "Created new taxonomy term for node/4312". Arrays printed with this function during module development are far less likely to wreck your beautiful page layout, and it also allows you to more easily see the content of your nodes during development, when contrasted with the dprint_r() function above.

You can pass two arguments to the dpm() function. The first is the variable and the second is the title and should be a string. For example, dpm($form, 'form'). This is incredibly useful when you have multiple dpm()'s on a page and need to know which one is which.

A note from the devel module: dsm() is a legacy function that was poorly named; use dpm() instead, since the 'p' maps to 'print_r'.

Modules

Based on Devel 6.x-1.18.

Devel

Various blocks, pages, and functions for developers. Depends on: Menu. Required by: Theme developer.

Devel generate

Generate dummy users, nodes, and taxonomy terms.

Devel node access

Developer block and page illustrating relevant node_access records.

Performance Logging

Logs detailed and/or summary page generation time and memory consumption for page requests.

Theme developer

Essential theme API information for theme developers. Depends on: Devel, Menu.

Devel

The Devel module adds the following options to Administer > Site configuration:

Devel settings

Helper functions, pages, and blocks to assist Drupal developers. The devel blocks can be managed via the block administration page.

Blocks

Blocks added by Devel:

  • Development
  • Execute PHP
  • Switch user

Tabs

Devel adds the following tabs to a node edit.

  • Dev load
  • Dev render

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.