drupal_find_theme_functions

Versions
6 – 7
drupal_find_theme_functions($cache, $prefixes)

Allow themes and/or theme engines to easily discover overridden theme functions.

Parameters

$cache The existing cache of theme hooks to test against.

$prefixes An array of prefixes to test, in reverse order of importance.

Return value

$templates The functions found, suitable for returning from hook_theme;

▾ 1 function calls drupal_find_theme_functions()

phptemplate_theme in themes/engines/phptemplate/phptemplate.engine
Implement hook_theme to tell Drupal what templates the engine and the current theme use. The $existing argument will contain hooks pre-defined by Drupal so that we can use that information if we need to.

Code

includes/theme.inc, line 989

<?php
function drupal_find_theme_functions($cache, $prefixes) {
  $templates = array();
  $functions = get_defined_functions();

  foreach ($cache as $hook => $info) {
    foreach ($prefixes as $prefix) {
      if (!empty($info['pattern'])) {
        $matches = preg_grep('/^' . $prefix . '_' . $info['pattern'] . '/', $functions['user']);
        if ($matches) {
          foreach ($matches as $match) {
            $new_hook = str_replace($prefix . '_', '', $match);
            $arg_name = isset($info['variables']) ? 'variables' : 'render element';
            $templates[$new_hook] = array(
              'function' => $match,
              $arg_name => $info[$arg_name],
            );
          }
        }
      }
      if (function_exists($prefix . '_' . $hook)) {
        $templates[$hook] = array(
          'function' => $prefix . '_' . $hook,
        );
        // Ensure that the pattern is maintained from base themes to its sub-themes.
        // Each sub-theme will have their functions scanned so the pattern must be
        // held for subsequent runs.
        if (isset($info['pattern'])) {
          $templates[$hook]['pattern'] = $info['pattern'];
        }
      }
    }
  }

  return $templates;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.