Hidden Drupal development functions

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?

[adsense:468x60:4496506397]

The dpr simply "saves carpal tunnel syndrome" (as the comment for the function in devel.module says) and the dvr function is funky useful as it not only dumps the data but also the data TYPE too (eg, is this variable a integer zero or boolean false?). The dpm and dvm functions are useful as the message only gets printed out on a visible page. This makes form output debuging easier.

Who here has debug outputted the $form_values on a form_submit and spent a few minutes wondering why nothing came up (due to the redirect after submit) and then ended up adding exit calls to the code to see the output or enabling the form redirection interruption from the Devel Module? Well if you use dpm or dvm then you will get the form output in a message on the next visible page without any workflow interruption! Cool, eh!

These are REALLY useful commands! Thanks to Moshe for adding the var_dump variants and I can only assume it was Moshe's idea to have the shortcut dpr and dpm functions to start with!

Comment Icon

8 Comments

The most recent comment was on Fri, 24th Aug 2012 - 11:28

I new these existed, but had forgot the actual function names. Thanks :)

If you scan devel.module you'll also see that these functions take arguments. Something I do when developing is stick dpr() in different hooks so I can track changes to an an object as it undergoes processing. This is a common one:

dpr($node, FALSE, __FUNCTION__.'->node');

This will dump $node to the screen along with the function name that fired it. If the second argument is TRUE it returns its value to the caller, which could be a logger function.

yeah, dsm is one dam cool function to use. and the best part is the location that is tells. There were quite a few instances during development where we used print_r and left for the day. next day we were not able to remember where that dam thing was getting printed :P

Functions are the best way to create links on a Drupal site. Thanks for the hidden functions. I really don't know about it.

Add new comment

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <img> <p>
  • You can use BBCode tags in the text. URLs will automatically be converted to links.
  • You can enable syntax highlighting of source code with the following tags: <code>, <pre>, <bash>, <css>, <html>, <js>, <jquery>, <mysql>, <php>. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.