Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hey I love this package!
I find it useful to use print_r() to get a good look at mysterious and/or buggy data structures. But I find the dprint_r() method you've included not quite enough. You can't control enough where it gets printed. What I do is add a theme method to pretty print variables. It let's me add code like this:
drupal_set_message(theme('devel', $obj)); // debug!
Anyway, here's a patch to do what I'm talking about. I hope it benefits others.
Comment | File | Size | Author |
---|---|---|---|
theme_devel.patch | 776 bytes | Dave Cohen | |
Comments
Comment #1
moshe weitzman CreditAttribution: moshe weitzman commentedwhere do you usually print the message? at first glance, i don't see that much value here.
Comment #2
Dave Cohen CreditAttribution: Dave Cohen commentedWhen I'm trying to track something down I often end up printing several messages. If I use print() they end up on the top of the page, often obscured by an absolutely positioned logo. If I use drupal_set_message(), they appear in a nice place, in the order I printed them, and even if I later perform a drupal_goto(), I see the messages on the next page. (Less need for that now thanks to the devel package.)
All my patch does is wrap the print_r() in an output buffer and return the string so it can be displayed later, when the page is being themed. You can take it or leave it, I won't be offended.
Comment #3
Dave Cohen CreditAttribution: Dave Cohen commentedAlso, you can use the theme function to insert an print_r into a watchdog message. But I'll shut up now.
Comment #4
merlinofchaos CreditAttribution: merlinofchaos commentedI would be just as happy if dprint and dprint_r could print the messages down with the SQL debug messages rather than at the top.
Comment #5
moshe weitzman CreditAttribution: moshe weitzman commentedboth sprint and dprint_r() can return strings instead of printing thus you can use drupalset_message on its return value if you wish.
Comment #6
Senpai CreditAttribution: Senpai commentedAnd just how would you go about this in a smooth, easy, and pretty way? This patch seems to hand things off to the theme layer for display, but by marking it as Won't Fix, it would appear that there's another way to do this same thing that's easier than the suggested patch.
So what is it? Can you give a quick example, please?