diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-07-02 04:27:23 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-07-02 04:27:23 +0000 |
commit | 0142292c718eaf31e73c3ee0cd9ef427bc18de16 (patch) | |
tree | 69e3a1784a48af68ec65537d375058bb2cb61daa /includes | |
parent | e9ca98b69d45b935fe4963a345cba92a87164ddb (diff) | |
download | brdo-0142292c718eaf31e73c3ee0cd9ef427bc18de16.tar.gz brdo-0142292c718eaf31e73c3ee0cd9ef427bc18de16.tar.bz2 |
#373201 by moshe weitzman, chx, Frando, eaton: Allow renderable array properties to be passed directly to theme functions.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/common.inc | 49 | ||||
-rw-r--r-- | includes/theme.inc | 30 |
2 files changed, 34 insertions, 45 deletions
diff --git a/includes/common.inc b/includes/common.inc index a1996a189..fb4aff11d 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -3663,28 +3663,6 @@ function drupal_render(&$elements) { } } - // Add additional CSS and JavaScript files associated with this element. - foreach (array('css', 'js') as $kind) { - if (!empty($elements['#attached_' . $kind]) && is_array($elements['#attached_' . $kind])) { - foreach ($elements['#attached_' . $kind] as $data => $options) { - // If the value is not an array, it's a filename and passed as first - // (and only) argument. - if (!is_array($options)) { - $data = $options; - $options = NULL; - } - // When drupal_add_js with 'type' => 'setting' is called, the first - // parameter ($data) is an array. Arrays can't be keys in PHP, so we - // have to get $data from the value array. - if (is_numeric($data)) { - $data = $options['data']; - unset($options['data']); - } - call_user_func('drupal_add_' . $kind, $data, $options); - } - } - } - // Get the children of the element, sorted by weight. $children = element_children($elements, TRUE); @@ -3716,6 +3694,28 @@ function drupal_render(&$elements) { } } } + + // Add additional CSS and JavaScript files associated with this element. + foreach (array('css', 'js') as $kind) { + if (!empty($elements['#attached_' . $kind]) && is_array($elements['#attached_' . $kind])) { + foreach ($elements['#attached_' . $kind] as $data => $options) { + // If the value is not an array, it's a filename and passed as first + // (and only) argument. + if (!is_array($options)) { + $data = $options; + $options = NULL; + } + // When drupal_add_js with 'type' => 'setting' is called, the first + // parameter ($data) is an array. Arrays can't be keys in PHP, so we + // have to get $data from the value array. + if (is_numeric($data)) { + $data = $options['data']; + unset($options['data']); + } + call_user_func('drupal_add_' . $kind, $data, $options); + } + } + } $prefix = isset($elements['#prefix']) ? $elements['#prefix'] : ''; $suffix = isset($elements['#suffix']) ? $elements['#suffix'] : ''; @@ -3982,9 +3982,6 @@ function drupal_common_theme() { 'item_list' => array( 'arguments' => array('items' => array(), 'title' => NULL, 'type' => 'ul', 'attributes' => NULL), ), - 'list' => array( - 'arguments' => array('elements' => NULL), - ), 'more_help_link' => array( 'arguments' => array('url' => NULL), ), @@ -4011,7 +4008,7 @@ function drupal_common_theme() { ), // from pager.inc 'pager' => array( - 'arguments' => array('tags' => array(), 'element' => 0, 'parameters' => array()), + 'arguments' => array('tags' => array(), 'element' => 0, 'parameters' => array(), 'quantity' => 9), ), 'pager_first' => array( 'arguments' => array('text' => NULL, 'element' => 0, 'parameters' => array()), diff --git a/includes/theme.inc b/includes/theme.inc index 7558d2b1d..41bdcf347 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -724,6 +724,17 @@ function theme() { if (isset($info['function'])) { // The theme call is a function. if (drupal_function_exists($info['function'])) { + // If a theme function that does not expect a renderable array is called + // with a renderable array as the only argument (via drupal_render), then + // we take the arguments from the properties of the renderable array. If + // missing, use hook_theme() defaults. + if (isset($args[0]) && is_array($args[0]) && isset($args[0]['#theme']) && count($info['arguments']) > 1) { + $new_args = array(); + foreach ($info['arguments'] as $name => $default) { + $new_args[] = isset($args[0]["#$name"]) ? $args[0]["#$name"] : $default; + } + $args = $new_args; + } $output = call_user_func_array($info['function'], $args); } } @@ -1659,25 +1670,6 @@ function theme_item_list($items = array(), $title = NULL, $type = 'ul', $attribu } /** - * Return a themed list of items from a drupal_render() style array. - * - * @param $elements - * An array consisting of the following keys: - * - #items: an array of items as expected by theme('item_list'). - * - #title: a title which prints above the list. - * - #list_type: the type of list to return. Defaults to "ul". - * - #attributes: an array of attributes as expected by theme('item_list'). - * @return - * A string containing the list output. - */ -function theme_list($elements) { - // Populate any missing array elements with their defaults. - $elements += element_info('list'); - - return theme('item_list', $elements['#items'], $elements['#title'], $elements['#list_type'], $elements['#attributes']); -} - -/** * Returns code that emits the 'more help'-link. */ function theme_more_help_link($url) { |