Main menu

Navigating with Krumo

The Devel module includes the super helpful Krumo library. I use dsm() and krumo() all the time. If you are not familiar with Devel, you should try it. Morten Wulff wrote a demo page for the module.

krumo

Today a client suggested that the Devel module Krumo could display the "path" to an item in an array by right clicking or otherwise interacting with the nested elements in the output from Krumo. I was really excited about that idea - I can't count the number of times I have tried and failed to target an item deep in a form array or an item in the node object simply because my human brain can't remember a structure like $form['#node']->content['links']['comment']['#attributes']['class'] for more than 3 seconds.

Still very happy with this new idea I went straight home and started to hack away at the Krumo library to make it display the path to a desired item. After looking at the javascript for a while, and saying out loud that Javascript hates me, I realized that the killer feature I was trying to make already exists in Krumo! This is a well hidden gem that I haven't seen before today, so I thought I would share it:
If you double click an item in the Krumo output it prints the items array "path" so that you can copy paste it into your code and stop worrying about remembering long array structures.

Thanks to Niels Fanøe for the inspiration.

krumo with array path

EDIT: I was using the dev D7 version, and the feature just went in this August. Thanks to Mark Theunissen for pointing that out. I also feel less stupid for not discovering the feature before now!

11 comments

by Litza on September 15, 2011 - 03:05

Thank you for sharing this! It's going to make life just a little bit more pleasant and elegant.

by Mark Theunissen on September 15, 2011 - 08:57

Just a note that this is only in the -dev version of the Devel module, it's not a feature of Krumo itself, and devel 7.x-1.2 doesn't have the patch yet (went in around August). :)

by naxoc on September 15, 2011 - 09:32

... It all now makes much more sense why I didn't see the feature before.

by Raf on September 15, 2011 - 11:20

I hope this feature makes it into the D6 version, too. It would save me so much scribbling papers that at least one rainforest-chopping company'd go out of business!

by xandeadx on September 16, 2011 - 08:41

where to download these changes?

by naxoc on September 16, 2011 - 08:55

xandeadx - download the 7.x-1.x-dev version: http://drupal.org/project/devel

by Niels Fanøe on September 16, 2011 - 13:54

Thanks for bringing this to our attention!

by valderama on September 16, 2011 - 21:21

great! I love this new feature of devel!

Thanks for sharing!

by akalata on September 21, 2011 - 03:31

Thanks for the heads-up!

by eiriksm on September 22, 2011 - 22:08

oh boy. This made my day. In like 3 hours I am going to wonder how the hell I made it through the day without this before.

I am very glad that you have put my little pet project Krumo to such good use. Unfortunately I do not have enough time the last several years to work on it, but I see that the Drupal community manages to fix all its shortcomings on their own.

Thanks again for all the kind words!

Post new comment

Drupal theme by Kiwi Themes.