A Poor Coder's Devel Themer Port for Drupal 5

Ethan's picture

Let me start by saying I’m not proud of this, it is one of those awful awful hacks which I should be ashamed of and appalled that I would even consider, one of those hideous violations of every coding standard known to good coders throughout the world.

What is this horrid, monstrous bit of code hackery I’m referring to? It’s a simple hack to the theme function which provides a very rudimentary version of some of the theme-level information so elegantly and profoundly usefully exposed by Moshe Weitzman’s Devel Themer module. For various reasons, this hack actually isn’t that egregious; for one it is ONLY FOR USE ON DEVELOPMENT SITES, and therefore does not all into that more loathsome category of coding dark secrets which are injected into codebases in the 11th hour to make Drupal conform to non-Drupal-tuned functional specifications. In addition, the hack allows custom processing of theme output to be included in the info dump for themed blocks, and therefore makes incredibly arduous tasks like finding the source of a missing </div> tag a great deal less awful. Let’s face it (with relish): sometimes hacking core is just the best way to debug difficult problems.

So, enough stalling, just what is this horrible, awful, shameful hack I’ve devised. Well, it’s anticlimactically simple, actually. Just insert the following code into the function theme() declaration in theme.inc just above the return call_user_func_array($functions[$function], $args) call:

 
/* BEGIN: poor coders devel themer hack to determine where content is being generated */    
  if (is_string($rtn)) {
    $odivs = substr_count($rtn, '<div');
    $cdivs = substr_count($rtn, '</div');
    $ne_divs = ($odivs!=$cdivs)?" NE_DIV_TAGS":'';
    return "<div class=\"THEMER-DUMP\" style=\"display:none\">\nSTART: " .
      $functions[$function] . " ($odivs,$cdivs)$ne_divs\n</div>" . $rtn . 
      "<div class=\"THEMER-DUMP\" style=\"display:none\">\nEND: " . 
      $functions[$function]    . " ($odivs,$cdivs)\n</div>";
  } else {
    return $rtn;
  }
  /* END: poor coders devel themer */
 

This code is tuned for finding unclosed div tags: at the end of every themer output dump is a count of open and close div tags. This was what I needed at the time, but there is no reason why additional data cannot be included. The code should be commented out except when needed and NEVER PUT ON PRODUCTION WEB SITES, but hopefully will be useful to some people (at least until a real port of the Devel Themer functions emerges for Drupal 5).

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockcode>
  • Lines and paragraphs break automatically.
  • You may post block code using <blockcode [type="language"]>...</blockcode> tags. You may also post inline code using <code [type="language"]>...</code> tags.

More information about formatting options

Captcha
Are you a robot? We usually like robots, but not in our comments.
Copy the characters (respecting upper/lower case) from the image.