Contributions API

Calling all Drupal developers!

Help us get this on the first page of Digg. DIGG NOW!

Modules in 6

devel_themer_catch_function

Definition

devel_themer_catch_function()
contributions/devel/devel_themer.module, line 167

Description

Intercepts all theme calls (including templates), adds to template log, and dispatches to original theme function. This function gets injected into theme registry in devel_exit().

Code

<?php
function devel_themer_catch_function() {
  $args = func_get_args();

  // Get the function that is normally called.
  $trace = debug_backtrace();
  $hook = $trace[2]['args'][0];
  array_unshift($args, $hook);

  $counter = devel_counter();
  $timer_name = "thmr_$counter";
  timer_start($timer_name);

  // The twin of theme(). All rendering done through here.
  list($return, $meta) = call_user_func_array('devel_themer_theme_twin', $args);
  $time = timer_stop($timer_name);

  $skip = array('hidden', 'form_element', 'placeholder');
  if (!empty($return) && !is_array($return) && !is_object($return) && user_access('access devel information')) {
    list($prefix, $suffix) = devel_theme_call_marker($hook, $counter, 'func');
    $start_return = substr($return, 0, 31);
    $start_prefix = substr($prefix, 0, 31);

    if ($start_return != $start_prefix && !in_array($hook, $skip)) {
      $output = $prefix. "\n  ". $return. $suffix. "\n";

      if ($meta['type'] == 'func') {
        $name = $meta['used'];
        $used = $meta['used'];
        if (empty($meta['wildcards'])) {
          $meta['wildcards'][$hook] = '';
        }  
        $candidates = devel_themer_ancestry(array_reverse(array_keys($meta['wildcards'])));
        if (empty($meta['variables'])) {
          $variables = array();
        }
        elseif (has_krumo()) {
          $variables = krumo_ob($meta['variables']);
        }
        else {
          $variables = devel_print_object($meta['variables'], NULL, FALSE);
        }
      }
      else {
        $name = $meta['used']. devel_themer_get_extension();
        if (empty($suggestions)) {
          array_unshift($meta['suggestions'], $meta['used']);
        }
        $candidates = array_reverse(array_map('devel_themer_append_extension', $meta['suggestions']));
        $used = $meta['template_file'];
        if (has_krumo()) {
          $variables = krumo_ob($meta['variables']);
        }
        else {
          $variables = devel_print_object($meta['variables'], '$', FALSE);
        }
      }

      $GLOBALS['devel_theme_calls']["thmr_$counter"] = array(
        'name' => $name,
        'type' => $meta['type'],
        'duration' => $time['time'],
        'used' => $used,
        'candidates' => $candidates,
        'args' => $variables,
      );
    }
    else {
      $output = $return;
    }
  }

  return isset($output) ? $output : $return;
}
?>