commit c465beadce8052bb618da6b761409598159e5cde Author: Joel Pittet Date: Fri Oct 11 01:17:39 2013 -0700 wrap in theme diff --git a/core/includes/theme.inc b/core/includes/theme.inc index e49bb76..e6b44c4 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1103,20 +1103,9 @@ function theme($hook, $variables = array()) { template_preprocess($default_template_variables, $hook, $info); $variables += $default_template_variables; } - if (!isset($default_attributes)) { - $default_attributes = new Attribute(); - } - foreach (array('attributes', 'title_attributes', 'content_attributes') as $key) { - if (isset($variables[$key]) && !($variables[$key] instanceof Attribute)) { - if ($variables[$key]) { - $variables[$key] = new Attribute($variables[$key]); - } - else { - // Create empty attributes. - $variables[$key] = clone $default_attributes; - } - } - } + + // Find all the #type => attributes and convert them to Attribute() objects. + wrap_type_attributes($variables); // Render the output using the template file. $template_file = $info['template'] . $extension; @@ -1142,6 +1131,26 @@ function theme($hook, $variables = array()) { } /** + * Recurivly converts any array of #type => attributes. + * + * @param array $variables + * An associative array of variables. + */ +function wrap_type_attributes(&$variables) { + foreach ($variables as $key => $value) { + if (is_array($value)) { + if (isset($value['#type']) && $value['#type'] == 'attributes') { + unset($variables[$key]['#type']); + $variables[$key] = new Attribute($variables[$key]); + } + else { + wrap_type_attributes($variables[$key]); + } + } + } +} + +/** * Returns the path to the current themed element. * * It can point to the active theme or the module handling a themed @@ -2462,9 +2471,15 @@ function template_preprocess(&$variables, $hook, $info) { function _template_preprocess_default_variables() { // Variables that don't depend on a database connection. $variables = array( - 'attributes' => array(), - 'title_attributes' => array(), - 'content_attributes' => array(), + 'attributes' => array( + '#type' => 'attributes', + ), + 'title_attributes' => array( + '#type' => 'attributes', + ), + 'content_attributes' => array( + '#type' => 'attributes', + ), 'title_prefix' => array(), 'title_suffix' => array(), 'db_is_active' => !defined('MAINTENANCE_MODE'),