Let's say, for instance, that I want to quickly view the variables sent to HOOK_preprocess_node()
, but I'm too lazy (if I'm just being honest) to edit my template.php file just to do that one check.
Can devel's Execute PHP block allow me to do something like this?
function SOMETHING_preprocess_node(&$vars) {
dpm($vars);
}
Or is it impossible to use hooks in this context?
To clarify, my somewhat lofty goal is to be able to experiment with virtually any hook function quickly using Devel's PHP execution, and if there's a syntax for doing that. I realize there are some problems with that concept from the get-go, not the least of which is that you need to artificially create a context in which certain hooks will even be called, but I want to see what's available.
EDIT: Tenken's answer got me thinking. I could create a global array called, say, $devel_hooks
. In a module, I could populate this variable with the contents of various hooks like so:
$devel_hooks = array();
function devhooks_preprocess_page(&vars) {
global $devel_hooks;
$devel_hooks['preprocess_page'] = $vars;
}
The contents of $devel_hooks
could then conceivably be accessed at will, BUT there's a problem: Devel's Execute PHP block evaluates its content immediately on form submit and before the page loads again, so I couldn't put, say, dpm($devel_hooks['preprocess_page']);
in there and get anything out of it because the page and its hooks haven't been processed yet, so $devel_hooks is completely empty or may even be undefined when that PHP is evaluated.
So maybe I could populate another global array with the information I want to request from $devel_hooks
, and have the latest possible page hook (which might be HOOK_page_alter()
?) parse that array and run a dpm()
on the requested components of $devel_hooks
. You would then, obviously, need to execute the PHP on a page that would use the desired hooks, but that's on you. I just haven't quite figured out how to connect those dots.
I could, conceivably, populate the array with strings and map those to array keys, but what if I want to dpm() something deeply nested in one of the hook arrays, like $devel_hooks['preprocess_node]['elements']['body']['#markup']
(just as an example, may not be accurate to what that array would look like)?