Commit a7149821 authored by webchick's avatar webchick

#600974 by effulgentsia, JohnAlbin, sun, and Damien Tournoud: Allow theme...

#600974 by effulgentsia, JohnAlbin, sun, and Damien Tournoud: Allow theme functions to take one argument without any hacks. NOTE: This is an API change in hook_theme().
parent f2d90e99
...@@ -5071,196 +5071,196 @@ function drupal_common_theme() { ...@@ -5071,196 +5071,196 @@ function drupal_common_theme() {
return array( return array(
// theme.inc // theme.inc
'placeholder' => array( 'placeholder' => array(
'arguments' => array('text' => NULL) 'variables' => array('text' => NULL)
), ),
'html' => array( 'html' => array(
'arguments' => array('page' => NULL), 'render element' => 'page',
'template' => 'html', 'template' => 'html',
), ),
'page' => array( 'page' => array(
'arguments' => array('page' => NULL), 'render element' => 'page',
'template' => 'page', 'template' => 'page',
), ),
'region' => array( 'region' => array(
'arguments' => array('elements' => NULL), 'render element' => 'elements',
'template' => 'region', 'template' => 'region',
), ),
'status_messages' => array( 'status_messages' => array(
'arguments' => array('display' => NULL), 'variables' => array('display' => NULL),
), ),
'links' => array( 'links' => array(
'arguments' => array('links' => NULL, 'attributes' => array('class' => array('links')), 'heading' => array()), 'variables' => array('links' => NULL, 'attributes' => array('class' => array('links')), 'heading' => array()),
), ),
'image' => array( 'image' => array(
'arguments' => array('path' => NULL, 'alt' => '', 'title' => '', 'attributes' => array(), 'getsize' => TRUE), 'variables' => array('path' => NULL, 'alt' => '', 'title' => '', 'attributes' => array(), 'getsize' => TRUE),
), ),
'breadcrumb' => array( 'breadcrumb' => array(
'arguments' => array('breadcrumb' => NULL), 'variables' => array('breadcrumb' => NULL),
), ),
'help' => array( 'help' => array(
'arguments' => array(), 'variables' => array(),
), ),
'submenu' => array( 'submenu' => array(
'arguments' => array('links' => NULL), 'variables' => array('links' => NULL),
), ),
'table' => array( 'table' => array(
'arguments' => array('header' => NULL, 'rows' => NULL, 'attributes' => array(), 'caption' => NULL, 'colgroups' => array(), 'sticky' => TRUE), 'variables' => array('header' => NULL, 'rows' => NULL, 'attributes' => array(), 'caption' => NULL, 'colgroups' => array(), 'sticky' => TRUE),
), ),
'table_select_header_cell' => array( 'table_select_header_cell' => array(
'arguments' => array(), 'variables' => array(),
), ),
'tablesort_indicator' => array( 'tablesort_indicator' => array(
'arguments' => array('style' => NULL), 'variables' => array('style' => NULL),
), ),
'mark' => array( 'mark' => array(
'arguments' => array('type' => MARK_NEW), 'variables' => array('type' => MARK_NEW),
), ),
'item_list' => array( 'item_list' => array(
'arguments' => array('items' => array(), 'title' => NULL, 'type' => 'ul', 'attributes' => array()), 'variables' => array('items' => array(), 'title' => NULL, 'type' => 'ul', 'attributes' => array()),
), ),
'more_help_link' => array( 'more_help_link' => array(
'arguments' => array('url' => NULL), 'variables' => array('url' => NULL),
), ),
'feed_icon' => array( 'feed_icon' => array(
'arguments' => array('url' => NULL, 'title' => NULL), 'variables' => array('url' => NULL, 'title' => NULL),
), ),
'more_link' => array( 'more_link' => array(
'arguments' => array('url' => NULL, 'title' => NULL) 'variables' => array('url' => NULL, 'title' => NULL)
), ),
'blocks' => array( 'blocks' => array(
'arguments' => array('region' => NULL), 'variables' => array('region' => NULL),
), ),
'username' => array( 'username' => array(
'arguments' => array('account' => NULL), 'variables' => array('account' => NULL),
), ),
'progress_bar' => array( 'progress_bar' => array(
'arguments' => array('percent' => NULL, 'message' => NULL), 'variables' => array('percent' => NULL, 'message' => NULL),
), ),
'indentation' => array( 'indentation' => array(
'arguments' => array('size' => 1), 'variables' => array('size' => 1),
), ),
// from theme.maintenance.inc // from theme.maintenance.inc
'maintenance_page' => array( 'maintenance_page' => array(
'arguments' => array('content' => NULL, 'show_messages' => TRUE), 'variables' => array('content' => NULL, 'show_messages' => TRUE),
'template' => 'maintenance-page', 'template' => 'maintenance-page',
), ),
'update_page' => array( 'update_page' => array(
'arguments' => array('content' => NULL, 'show_messages' => TRUE), 'variables' => array('content' => NULL, 'show_messages' => TRUE),
), ),
'install_page' => array( 'install_page' => array(
'arguments' => array('content' => NULL), 'variables' => array('content' => NULL),
), ),
'task_list' => array( 'task_list' => array(
'arguments' => array('items' => NULL, 'active' => NULL), 'variables' => array('items' => NULL, 'active' => NULL),
), ),
'authorize_message' => array( 'authorize_message' => array(
'arguments' => array('message' => NULL, 'success' => TRUE), 'variables' => array('message' => NULL, 'success' => TRUE),
), ),
'authorize_report' => array( 'authorize_report' => array(
'arguments' => array('messages' => array()), 'variables' => array('messages' => array()),
), ),
// from pager.inc // from pager.inc
'pager' => array( 'pager' => array(
'arguments' => array('tags' => array(), 'element' => 0, 'parameters' => array(), 'quantity' => 9), 'variables' => array('tags' => array(), 'element' => 0, 'parameters' => array(), 'quantity' => 9),
), ),
'pager_first' => array( 'pager_first' => array(
'arguments' => array('text' => NULL, 'element' => 0, 'parameters' => array()), 'variables' => array('text' => NULL, 'element' => 0, 'parameters' => array()),
), ),
'pager_previous' => array( 'pager_previous' => array(
'arguments' => array('text' => NULL, 'element' => 0, 'interval' => 1, 'parameters' => array()), 'variables' => array('text' => NULL, 'element' => 0, 'interval' => 1, 'parameters' => array()),
), ),
'pager_next' => array( 'pager_next' => array(
'arguments' => array('text' => NULL, 'element' => 0, 'interval' => 1, 'parameters' => array()), 'variables' => array('text' => NULL, 'element' => 0, 'interval' => 1, 'parameters' => array()),
), ),
'pager_last' => array( 'pager_last' => array(
'arguments' => array('text' => NULL, 'element' => 0, 'parameters' => array()), 'variables' => array('text' => NULL, 'element' => 0, 'parameters' => array()),
), ),
'pager_link' => array( 'pager_link' => array(
'arguments' => array('text' => NULL, 'page_new' => NULL, 'element' => NULL, 'parameters' => array(), 'attributes' => array()), 'variables' => array('text' => NULL, 'page_new' => NULL, 'element' => NULL, 'parameters' => array(), 'attributes' => array()),
), ),
// from locale.inc // from locale.inc
'locale_admin_manage_screen' => array( 'locale_admin_manage_screen' => array(
'arguments' => array('form' => NULL), 'render element' => 'form',
), ),
// from menu.inc // from menu.inc
'menu_link' => array( 'menu_link' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'menu_tree' => array( 'menu_tree' => array(
'arguments' => array('tree' => NULL), 'render element' => 'tree',
), ),
'menu_local_task' => array( 'menu_local_task' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'menu_local_action' => array( 'menu_local_action' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'menu_local_tasks' => array( 'menu_local_tasks' => array(
'arguments' => array(), 'variables' => array(),
), ),
// from form.inc // from form.inc
'select' => array( 'select' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'fieldset' => array( 'fieldset' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'radio' => array( 'radio' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'radios' => array( 'radios' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'date' => array( 'date' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'checkbox' => array( 'checkbox' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'checkboxes' => array( 'checkboxes' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'button' => array( 'button' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'image_button' => array( 'image_button' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'hidden' => array( 'hidden' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'textfield' => array( 'textfield' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'form' => array( 'form' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'textarea' => array( 'textarea' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'markup' => array( 'markup' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'password' => array( 'password' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'file' => array( 'file' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'tableselect' => array( 'tableselect' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'form_element' => array( 'form_element' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'text_format_wrapper' => array( 'text_format_wrapper' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'vertical_tabs' => array( 'vertical_tabs' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
'container' => array( 'container' => array(
'arguments' => array('element' => NULL), 'render element' => 'element',
), ),
); );
} }
......
...@@ -299,11 +299,15 @@ function drupal_theme_rebuild() { ...@@ -299,11 +299,15 @@ function drupal_theme_rebuild() {
* - 'template': The filename of the template generating output for this * - 'template': The filename of the template generating output for this
* theme hook. The template is in the directory defined by the 'path' key of * theme hook. The template is in the directory defined by the 'path' key of
* hook_theme() or defaults to $path. * hook_theme() or defaults to $path.
* - 'arguments': The arguments for this theme hook as defined in * - 'variables': The variables for this theme hook as defined in
* hook_theme(). If there is more than one implementation and 'arguments' is * hook_theme(). If there is more than one implementation and 'variables' is
* not specified in a later one, then the previous definition is kept. * 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 * - 'theme paths': The paths where implementations of a theme hook can be
* found. Its definition is similarly inherited like 'arguments'. Each time * found. Its definition is similarly inherited like 'variables'. Each time
* _theme_process_registry() is called for this theme hook, either the * _theme_process_registry() is called for this theme hook, either the
* 'path' key from hook_theme() (if defined) or $path is added. * 'path' key from hook_theme() (if defined) or $path is added.
* - 'preprocess functions': See theme() for detailed documentation. * - 'preprocess functions': See theme() for detailed documentation.
...@@ -365,11 +369,15 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) { ...@@ -365,11 +369,15 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) {
$result[$hook]['includes'][] = $include_file; $result[$hook]['includes'][] = $include_file;
} }
// If 'arguments' have been defined previously, carry them forward. // If 'variables' have been defined previously, carry them forward.
// This should happen if a theme overrides a Drupal defined theme // This should happen if a theme overrides a Drupal defined theme
// function, for example. // function, for example.
if (!isset($info['arguments']) && isset($cache[$hook])) { if (!isset($info['variables']) && isset($cache[$hook]['variables'])) {
$result[$hook]['arguments'] = $cache[$hook]['arguments']; $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. // The following apply only to theming hooks implemented as templates.
...@@ -780,30 +788,28 @@ function theme($hook, $variables = array()) { ...@@ -780,30 +788,28 @@ function theme($hook, $variables = array()) {
} }
// If a renderable array is passed as $variables, then set $variables to // If a renderable array is passed as $variables, then set $variables to
// what's expected by the theme hook. If the theme hook expects a single // the arguments expected by the theme function.
// argument, set the renderable array as that argument. If the theme hook
// expects multiple arguments, set the properties of the renderable array as
// those arguments.
if (isset($variables['#theme']) || isset($variables['#theme_wrappers'])) { if (isset($variables['#theme']) || isset($variables['#theme_wrappers'])) {
$element = $variables; $element = $variables;
$variables = array(); $variables = array();
$n = count($info['arguments']); if (isset($info['variables'])) {
if ($n == 1) { foreach (array_keys($info['variables']) as $name) {
$arg_keys = array_keys($info['arguments']);
$variables[$arg_keys[0]] = $element;
}
elseif ($n > 1) {
foreach ($info['arguments'] as $name => $default) {
if (isset($element["#$name"])) { if (isset($element["#$name"])) {
$variables[$name] = $element["#$name"]; $variables[$name] = $element["#$name"];
} }
} }
} }
else {
$variables[$info['render element']] = $element;
}
} }
// Merge in argument defaults. // Merge in argument defaults.
if (!empty($info['arguments'])) { if (!empty($info['variables'])) {
$variables += $info['arguments']; $variables += $info['variables'];
}
elseif (!empty($info['render element'])) {
$variables += array($info['render element'] => array());
} }
// Invoke the variable processors, if any. The processors may specify // Invoke the variable processors, if any. The processors may specify
...@@ -968,8 +974,7 @@ function path_to_theme() { ...@@ -968,8 +974,7 @@ function path_to_theme() {
} }
/** /**
* Find overridden theme functions. Called by themes and/or theme engines to * Allow themes and/or theme engines to easily discover overridden theme functions.
* easily discover theme functions.
* *
* @param $cache * @param $cache
* The existing cache of theme hooks to test against. * The existing cache of theme hooks to test against.
...@@ -990,9 +995,10 @@ function drupal_find_theme_functions($cache, $prefixes) { ...@@ -990,9 +995,10 @@ function drupal_find_theme_functions($cache, $prefixes) {
if ($matches) { if ($matches) {
foreach ($matches as $match) { foreach ($matches as $match) {
$new_hook = str_replace($prefix . '_', '', $match); $new_hook = str_replace($prefix . '_', '', $match);
$arg_name = isset($info['variables']) ? 'variables' : 'render element';
$templates[$new_hook] = array( $templates[$new_hook] = array(
'function' => $match, 'function' => $match,
'arguments' => $info['arguments'], $arg_name => $info[$arg_name],
); );
} }
} }
...@@ -1015,8 +1021,7 @@ function drupal_find_theme_functions($cache, $prefixes) { ...@@ -1015,8 +1021,7 @@ function drupal_find_theme_functions($cache, $prefixes) {
} }
/** /**
* Find overridden theme templates. Called by themes and/or theme engines to * Allow themes and/or theme engines to easily discover overridden templates.
* easily discover templates.
* *
* @param $cache * @param $cache
* The existing cache of theme hooks to test against. * The existing cache of theme hooks to test against.
...@@ -1093,10 +1098,11 @@ function drupal_find_theme_templates($cache, $extension, $path) { ...@@ -1093,10 +1098,11 @@ function drupal_find_theme_templates($cache, $extension, $path) {
foreach ($matches as $match) { foreach ($matches as $match) {
$file = substr($match, 0, strpos($match, '.')); $file = substr($match, 0, strpos($match, '.'));
// Put the underscores back in for the hook name and register this pattern. // Put the underscores back in for the hook name and register this pattern.
$arg_name = isset($info['variables']) ? 'variables' : 'render element';
$templates[strtr($file, '-', '_')] = array( $templates[strtr($file, '-', '_')] = array(
'template' => $file, 'template' => $file,
'path' => dirname($files[$match]->uri), 'path' => dirname($files[$match]->uri),
'arguments' => $info['arguments'], $arg_name => $info[$arg_name],
); );
} }
} }
......
...@@ -40,43 +40,43 @@ function aggregator_help($path, $arg) { ...@@ -40,43 +40,43 @@ function aggregator_help($path, $arg) {
function aggregator_theme() { function aggregator_theme() {
return array( return array(
'aggregator_wrapper' => array( 'aggregator_wrapper' => array(
'arguments' => array('content' => NULL), 'variables' => array('content' => NULL),
'file' => 'aggregator.pages.inc', 'file' => 'aggregator.pages.inc',
'template' => 'aggregator-wrapper', 'template' => 'aggregator-wrapper',
), ),
'aggregator_categorize_items' => array( 'aggregator_categorize_items' => array(
'arguments' => array('form' => NULL), 'render element' => 'form',
'file' => 'aggregator.pages.inc', 'file' => 'aggregator.pages.inc',
), ),
'aggregator_feed_source' => array( 'aggregator_feed_source' => array(
'arguments' => array('feed' => NULL), 'variables' => array('feed' => NULL),
'file' => 'aggregator.pages.inc', 'file' => 'aggregator.pages.inc',
'template' => 'aggregator-feed-source', 'template' => 'aggregator-feed-source',
), ),
'aggregator_block_item' => array( 'aggregator_block_item' => array(
'arguments' => array('item' => NULL, 'feed' => 0), 'variables' => array('item' => NULL, 'feed' => 0),
), ),
'aggregator_summary_items' => array( 'aggregator_summary_items' => array(
'arguments' => array('summary_items' => NULL, 'source' => NULL), 'variables' => array('summary_items' => NULL, 'source' => NULL),
'file' => 'aggregator.pages.inc', 'file' => 'aggregator.pages.inc',
'template' => 'aggregator-summary-items', 'template' => 'aggregator-summary-items',
), ),
'aggregator_summary_item' => array( 'aggregator_summary_item' => array(
'arguments' => array('item' => NULL), 'variables' => array('item' => NULL),
'file' => 'aggregator.pages.inc', 'file' => 'aggregator.pages.inc',
'template' => 'aggregator-summary-item', 'template' => 'aggregator-summary-item',
), ),
'aggregator_item' => array( 'aggregator_item' => array(
'arguments' => array('item' => NULL), 'variables' => array('item' => NULL),
'file' => 'aggregator.pages.inc', 'file' => 'aggregator.pages.inc',
'template' => 'aggregator-item', 'template' => 'aggregator-item',
), ),
'aggregator_page_opml' => array( 'aggregator_page_opml' => array(
'arguments' => array('feeds' => NULL), 'variables' => array('feeds' => NULL),
'file' => 'aggregator.pages.inc', 'file' => 'aggregator.pages.inc',
), ),
'aggregator_page_rss' => array( 'aggregator_page_rss' => array(
'arguments' => array('feeds' => NULL, 'category' => NULL), 'variables' => array('feeds' => NULL, 'category' => NULL),
'file' => 'aggregator.pages.inc', 'file' => 'aggregator.pages.inc',
), ),
); );
......
...@@ -47,13 +47,13 @@ function block_help($path, $arg) { ...@@ -47,13 +47,13 @@ function block_help($path, $arg) {
function block_theme() { function block_theme() {
return array( return array(
'block' => array( 'block' => array(
'arguments' => array('elements' => NULL), 'render element' => 'elements',
'template' => 'block', 'template' => 'block',
), ),
'block_admin_display_form' => array( 'block_admin_display_form' => array(
'template' => 'block-admin-display-form', 'template' => 'block-admin-display-form',
'file' => 'block.admin.inc', 'file' => 'block.admin.inc',
'arguments' => array('form' => NULL), 'render element' => 'form',
), ),
); );
} }
......
...@@ -12,25 +12,25 @@ ...@@ -12,25 +12,25 @@
function book_theme() { function book_theme() {
return array( return array(
'book_navigation' => array( 'book_navigation' => array(
'arguments' => array('book_link' => NULL), 'variables' => array('book_link' => NULL),
'template' => 'book-navigation', 'template' => 'book-navigation',
), ),
'book_export_html' => array( 'book_export_html' => array(
'arguments' => array('title' => NULL, 'contents' => NULL, 'depth' => NULL), 'variables' => array('title' => NULL, 'contents' => NULL, 'depth' => NULL),
'template' => 'book-export-html', 'template' => 'book-export-html',
), ),
'book_admin_table' => array( 'book_admin_table' => array(
'arguments' => array('form' => NULL), 'render element' => 'form',
), ),
'book_title_link' => array( 'book_title_link' => array(
'arguments' => array('link' => NULL), 'variables' => array('link' => NULL),
), ),
'book_all_books_block' => array( 'book_all_books_block' => array(
'arguments' => array('book_menus' => array()), 'render element' => 'book_menus',
'template' => 'book-all-books-block', 'template' => 'book-all-books-block',
), ),
'book_node_export_html' => array( 'book_node_export_html' => array(
'arguments' => array('node' => NULL, 'children' => NULL), 'variables' => array('node' => NULL, 'children' => NULL),
'template' => 'book-node-export-html', 'template' => 'book-node-export-html',
), ),
); );
......
...@@ -22,7 +22,7 @@ function color_help($path, $arg) { ...@@ -22,7 +22,7 @@ function color_help($path, $arg) {
function color_theme() { function color_theme() {
return array( return array(
'color_scheme_form' => array( 'color_scheme_form' => array(
'arguments' => array('form' => NULL), 'render element' => 'form',
), ),
); );
} }
......
...@@ -122,21 +122,21 @@ function comment_entity_info() { ...@@ -122,21 +122,21 @@ function comment_entity_info() {
function comment_theme() { function comment_theme() {
return array( return array(
'comment_block' => array( 'comment_block' => array(
'arguments' => array(), 'variables' => array(),
), ),
'comment_preview' => array( 'comment_preview' => array(
'arguments' => array('comment' => NULL), 'variables' => array('comment' => NULL),
), ),
'comment' => array( 'comment' => array(