summaryrefslogtreecommitdiff
path: root/includes/theme.inc
diff options
context:
space:
mode:
Diffstat (limited to 'includes/theme.inc')
-rw-r--r--includes/theme.inc82
1 files changed, 46 insertions, 36 deletions
diff --git a/includes/theme.inc b/includes/theme.inc
index c5015865d..3ae50006a 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -1,5 +1,4 @@
<?php
-// $Id$
/**
* @file
@@ -104,7 +103,7 @@ function drupal_theme_initialize() {
drupal_static_reset('drupal_alter');
// Provide the page with information about the theme that's used, so that a
- // later AJAX request can be rendered using the same theme.
+ // later Ajax request can be rendered using the same theme.
// @see ajax_base_page_theme()
$setting['ajaxPageState'] = array(
'theme' => $theme_key,
@@ -320,8 +319,8 @@ function drupal_theme_rebuild() {
* 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.
+ * - '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.
@@ -363,7 +362,6 @@ function drupal_theme_rebuild() {
*/
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.
@@ -372,24 +370,43 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) {
'process functions' => 'process',
);
+ $hook_defaults = array(
+ 'variables' => TRUE,
+ 'render element' => TRUE,
+ 'pattern' => TRUE,
+ 'base hook' => TRUE,
+ );
+
+ // Invoke the hook_theme() implementation, process what is returned, and
+ // merge it into $cache.
+ $function = $name . '_theme';
if (function_exists($function)) {
$result = $function($cache, $type, $theme, $path);
foreach ($result as $hook => $info) {
+ // When a theme or engine overrides a module's theme function
+ // $result[$hook] will only contain key/value pairs for information being
+ // overridden. Pull the rest of the information from what was defined by
+ // an earlier hook.
+
+ // Fill in the type and path of the module, theme, or engine that
+ // implements this theme function.
$result[$hook]['type'] = $type;
$result[$hook]['theme path'] = $path;
- // if function and file are left out, default to standard naming
+
+ // If function and file are omitted, 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 the theme implementation defines a file, then also use the path
+ // that it defined. Otherwise use the default path. This allows
+ // system.module to declare theme functions on behalf of core .include
+ // files.
if (isset($info['file'])) {
$include_file = isset($info['path']) ? $info['path'] : $path;
$include_file .= '/' . $info['file'];
@@ -397,14 +414,10 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) {
$result[$hook]['includes'][] = $include_file;
}
- // If these keys are left unspecified within overridden entries returned
- // by hook_theme(), carry them forward from the prior entry. This is so
- // that themes don't need to specify this information, since the module
- // that registered the theme hook already has.
- foreach (array('variables', 'render element', 'pattern', 'base hook') as $key) {
- if (!isset($info[$key]) && isset($cache[$hook][$key])) {
- $result[$hook][$key] = $cache[$hook][$key];
- }
+ // If the default keys are not set, use the default values registered
+ // by the module.
+ if (isset($cache[$hook])) {
+ $result[$hook] += array_intersect_key($cache[$hook], $hook_defaults);
}
// The following apply only to theming hooks implemented as templates.
@@ -469,7 +482,7 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) {
}
// Merge the newly created theme hooks into the existing cache.
- $cache = array_merge($cache, $result);
+ $cache = $result + $cache;
}
// Let themes have variable processors even if they didn't register a template.
@@ -972,7 +985,7 @@ function drupal_find_theme_functions($cache, $prefixes) {
// start with. The default is the name of the hook followed by '__'. An
// 'base hook' key is added to each entry made for a found suggestion,
// so that common functionality can be implemented for all suggestions of
- // the same base hook. To keep things simple, deep heirarchy of
+ // the same base hook. To keep things simple, deep hierarchy of
// suggestions is not supported: each suggestion's 'base hook' key
// refers to a base hook, not to another suggestion, and all suggestions
// are found using the base hook's pattern, not a pattern from an
@@ -982,7 +995,7 @@ function drupal_find_theme_functions($cache, $prefixes) {
$matches = preg_grep('/^' . $prefix . '_' . $pattern . '/', $functions['user']);
if ($matches) {
foreach ($matches as $match) {
- $new_hook = str_replace($prefix . '_', '', $match);
+ $new_hook = substr($match, strlen($prefix) + 1);
$arg_name = isset($info['variables']) ? 'variables' : 'render element';
$implementations[$new_hook] = array(
'function' => $match,
@@ -1256,15 +1269,8 @@ function theme_enable($theme_list) {
menu_rebuild();
drupal_theme_rebuild();
- // Notify locale module about new themes being enabled, so translations can
- // be imported. This might start a batch, and only return to the redirect
- // path after that.
- module_invoke('locale', 'system_update', $theme_list);
-
- // Invoke hook_themes_enabled after the themes have been enabled.
+ // Invoke hook_themes_enabled() after the themes have been enabled.
module_invoke_all('themes_enabled', $theme_list);
-
- return;
}
/**
@@ -1296,10 +1302,8 @@ function theme_disable($theme_list) {
menu_rebuild();
drupal_theme_rebuild();
- // Invoke hook_themes_enabled after the themes have been enabled.
+ // Invoke hook_themes_disabled after the themes have been disabled.
module_invoke_all('themes_disabled', $theme_list);
-
- return;
}
/**
@@ -1756,10 +1760,10 @@ function theme_table($variables) {
*/
function theme_tablesort_indicator($variables) {
if ($variables['style'] == "asc") {
- return theme('image', array('path' => 'misc/arrow-asc.png', 'alt' => t('sort ascending'), 'title' => t('sort ascending')));
+ return theme('image', array('path' => 'misc/arrow-asc.png', 'width' => 13, 'height' => 13, 'alt' => t('sort ascending'), 'title' => t('sort ascending')));
}
else {
- return theme('image', array('path' => 'misc/arrow-desc.png', 'alt' => t('sort descending'), 'title' => t('sort descending')));
+ return theme('image', array('path' => 'misc/arrow-desc.png', 'width' => 13, 'height' => 13, 'alt' => t('sort descending'), 'title' => t('sort descending')));
}
}
@@ -1872,7 +1876,7 @@ function theme_more_help_link($variables) {
*/
function theme_feed_icon($variables) {
$text = t('Subscribe to @feed-title', array('@feed-title' => $variables['title']));
- if ($image = theme('image', array('path' => 'misc/feed.png', 'alt' => $text))) {
+ if ($image = theme('image', array('path' => 'misc/feed.png', 'width' => 16, 'height' => 16, 'alt' => $text))) {
return l($image, $variables['url'], array('html' => TRUE, 'attributes' => array('class' => array('feed-icon'), 'title' => $text)));
}
}
@@ -2042,6 +2046,9 @@ function _theme_table_cell($cell, $header = FALSE) {
* Adds a default set of helper variables for variable processors and templates.
* This comes in before any other preprocess function which makes it possible to
* be used in default theme implementations (non-overridden theme functions).
+ *
+ * For more detailed information, see theme().
+ *
*/
function template_preprocess(&$variables, $hook) {
global $user;
@@ -2119,6 +2126,9 @@ function _template_preprocess_default_variables() {
/**
* A default process function used to alter variables as late as possible.
+ *
+ * For more detailed information, see theme().
+ *
*/
function template_process(&$variables, $hook) {
// Flatten out classes.