_theme_process_registry
- Versions
- 6 – 7
_theme_process_registry(&$cache, $name, $type, $theme, $path)
Process a single implementation of hook_theme().
See also
theme()
@see _theme_process_registry()
See also
@see list_themes()
Parameters
$cache The theme registry that will eventually be cached; It is an associative array keyed by theme hooks, whose values are associative arrays describing the hook:
- 'type': The passed in $type.
- 'theme path': The passed in $path.
- 'function': The name of the function generating output for this theme hook. Either defined explicitly in hook_theme() or, if neither 'function' nor 'template' is defined, then the default theme function name is used. The default theme function name is the theme hook prefixed by either 'theme_' for modules or '$name_' for everything else. If 'function' is defined, 'template' is not used.
- 'template': The filename of the template generating output for this theme hook. The template is in the directory defined by the 'path' key of hook_theme() or defaults to $path.
- 'variables': The variables for this theme hook as defined in hook_theme(). If there is more than one implementation and 'variables' is not specified in a later one, then the previous definition is kept.
- 'render element': The renderable element for this theme hook as defined in hook_theme(). If there is more than one implementation and 'render element' is not specified in a later one, then the previous definition is kept.
- 'theme paths': The paths where implementations of a theme hook can be found. Its definition is similarly inherited like 'variables'. Each time _theme_process_registry() is called for this theme hook, either the 'path' key from hook_theme() (if defined) or $path is added.
- 'preprocess functions': See theme() for detailed documentation.
- 'process functions': See theme() for detailed documentation.
$name The name of the module, theme engine, base theme engine, theme or base theme implementing hook_theme().
$type One of 'module', 'theme_engine', 'base_theme_engine', 'theme', or 'base_theme'. Unlike regular hooks that can only be implemented by modules, each of these can implement hook_theme(). _theme_process_registry() is called in aforementioned order and new entries override older ones. For example, if a theme hook is both defined by a module and a theme, then the definition in the theme will be used.
$theme The loaded $theme object as returned from list_themes().
$path The directory where $name is. For example, modules/system or themes/garland.
Code
includes/theme.inc, line 338
<?php
function _theme_process_registry(&$cache, $name, $type, $theme, $path) {
$result = array();
$function = $name . '_theme';
// Processor functions work in two distinct phases with the process
// functions always being executed after the preprocess functions.
$variable_process_phases = array(
'preprocess functions' => 'preprocess',
'process functions' => 'process',
);
if (function_exists($function)) {
$result = $function($cache, $type, $theme, $path);
foreach ($result as $hook => $info) {
$result[$hook]['type'] = $type;
$result[$hook]['theme path'] = $path;
// if function and file are left out, default to standard naming
// conventions.
if (!isset($info['template']) && !isset($info['function'])) {
$result[$hook]['function'] = ($type == 'module' ? 'theme_' : $name . '_') . $hook;
}
// If a path is set in the info, use what was set. Otherwise use the
// default path. This is mostly so system.module can declare theme
// functions on behalf of core .include files.
// All files are included to be safe. Conditionally included
// files can prevent them from getting registered.
if (isset($cache[$hook]['includes'])) {
$result[$hook]['includes'] = $cache[$hook]['includes'];
}
if (isset($info['file'])) {
$include_file = isset($info['path']) ? $info['path'] : $path;
$include_file .= '/' . $info['file'];
include_once DRUPAL_ROOT . '/' . $include_file;
$result[$hook]['includes'][] = $include_file;
}
// If 'variables' have been defined previously, carry them forward.
// This should happen if a theme overrides a Drupal defined theme
// function, for example.
if (!isset($info['variables']) && isset($cache[$hook]['variables'])) {
$result[$hook]['variables'] = $cache[$hook]['variables'];
}
// Same for 'render element'.
if (!isset($info['render element']) && isset($cache[$hook]['render element'])) {
$result[$hook]['render element'] = $cache[$hook]['render element'];
}
// The following apply only to theming hooks implemented as templates.
if (isset($info['template'])) {
// Prepend the current theming path when none is set.
if (!isset($info['path'])) {
$result[$hook]['template'] = $path . '/' . $info['template'];
}
// These are used for template naming suggestions. Theme implementations
// can occur in multiple paths. Suggestions should follow.
if (!isset($info['theme paths']) && isset($cache[$hook])) {
$result[$hook]['theme paths'] = $cache[$hook]['theme paths'];
}
// Check for sub-directories.
$result[$hook]['theme paths'][] = isset($info['path']) ? $info['path'] : $path;
}
// Allow variable processors for all theming hooks, whether the hook is
// implemented as a template or as a function.
foreach ($variable_process_phases as $phase_key => $phase) {
// Check for existing variable processors. Ensure arrayness.
if (!isset($info[$phase_key]) || !is_array($info[$phase_key])) {
$info[$phase_key] = array();
$prefixes = array();
if ($type == 'module') {
// Default variable processor prefix.
$prefixes[] = 'template';
// Add all modules so they can intervene with their own variable
// processors. This allows them to provide variable processors even
// if they are not the owner of the current hook.
$prefixes += module_list();
}
elseif ($type == 'theme_engine' || $type == 'base_theme_engine') {
// Theme engines get an extra set that come before the normally
// named variable processors.
$prefixes[] = $name . '_engine';
// The theme engine registers on behalf of the theme using the
// theme's name.
$prefixes[] = $theme;
}
else {
// This applies when the theme manually registers their own variable
// processors.
$prefixes[] = $name;
}
foreach ($prefixes as $prefix) {
// Only use non-hook-specific variable processors for theming hooks
// implemented as templates. @see theme().
if (isset($info['template']) && function_exists($prefix . '_' . $phase)) {
$info[$phase_key][] = $prefix . '_' . $phase;
}
if (function_exists($prefix . '_' . $phase . '_' . $hook)) {
$info[$phase_key][] = $prefix . '_' . $phase . '_' . $hook;
}
}
}
// Check for the override flag and prevent the cached variable
// processors from being used. This allows themes or theme engines to
// remove variable processors set earlier in the registry build.
if (!empty($info['override ' . $phase_key])) {
// Flag not needed inside the registry.
unset($result[$hook]['override ' . $phase_key]);
}
elseif (isset($cache[$hook][$phase_key]) && is_array($cache[$hook][$phase_key])) {
$info[$phase_key] = array_merge($cache[$hook][$phase_key], $info[$phase_key]);
}
$result[$hook][$phase_key] = $info[$phase_key];
}
}
// Merge the newly created theme hooks into the existing cache.
$cache = array_merge($cache, $result);
}
// Let themes have variable processors even if they didn't register a template.
if ($type == 'theme' || $type == 'base_theme') {
foreach ($cache as $hook => $info) {
// Check only if not registered by the theme or engine.
if (empty($result[$hook])) {
foreach ($variable_process_phases as $phase_key => $phase) {
if (!isset($info[$phase_key])) {
$cache[$hook][$phase_key] = array();
}
// Only use non-hook-specific variable processors for theming hooks
// implemented as templates. @see theme().
if (isset($info['template']) && function_exists($name . '_' . $phase)) {
$cache[$hook][$phase_key][] = $name . '_' . $phase;
}
if (function_exists($name . '_' . $phase . '_' . $hook)) {
$cache[$hook][$phase_key][] = $name . '_' . $phase . '_' . $hook;
}
// Ensure uniqueness.
$cache[$hook][$phase_key] = array_unique($cache[$hook][$phase_key]);
}
}
}
}
}
?>Login or register to post comments 