#601806 by Damien Tournoud: make sure that hook_element_info_alter() can alter default properties.

From: damz <damz@devland.local>


---
 common.inc                      |   42 +++++++++++++++++----------------------
 image/image.admin.inc           |    2 +-
 simpletest/simpletest.pages.inc |    2 +-
 system/system.admin.inc         |    2 +-
 4 files changed, 21 insertions(+), 27 deletions(-)

diff --git includes/common.inc includes/common.inc
index 7693b90..6786e38 100644
--- includes/common.inc
+++ includes/common.inc
@@ -4614,7 +4614,6 @@ function drupal_render_page($page) {
  *   The rendered HTML.
  */
 function drupal_render(&$elements) {
-  static $defaults;
   // Early-return nothing if user does not have access.
   if (!isset($elements) || (isset($elements['#access']) && !$elements['#access'])) {
     return;
@@ -4632,14 +4631,9 @@ function drupal_render(&$elements) {
 
   // If the default values for this element have not been loaded yet, populate
   // them.
-  if (isset($elements['#type']) && empty($elements['#defaults_loaded'])) {
-    $elements += element_info($elements['#type']);
-  }
-  else {
-    if (!isset($defaults)) {
-      $defaults = element_basic_defaults();
-    }
-    $elements += $defaults;
+  if (empty($elements['#defaults_loaded'])) {
+    $elements += element_info(isset($elements['#type']) ? $elements['#type'] : 'defaults');
+    $elements['#defaults_loaded'] = TRUE;
   }
 
   // If #markup is not empty and no theme function is set, use theme_markup.
@@ -4926,30 +4920,30 @@ function element_info($type) {
   $cache = &drupal_static(__FUNCTION__);
 
   if (!isset($cache)) {
-    $basic_defaults = element_basic_defaults();
+    $basic_defaults = array(
+      '#description' => '',
+      '#title' => '',
+      '#attributes' => array(),
+      '#required' => FALSE,
+      '#attached' => array(),
+    );
+
+    // Load all the elements, keyed by their #type.
     $cache = module_invoke_all('element_info');
+
     foreach ($cache as $element_type => $info) {
       $cache[$element_type] = array_merge_recursive($basic_defaults, $info);
       $cache[$element_type]['#type'] = $element_type;
     }
+
+    // Add default properties.
+    $cache['defaults'] = $basic_defaults;
+
     // Allow modules to alter the element type defaults.
     drupal_alter('element_info', $cache);
   }
 
-  return isset($cache[$type]) ? $cache[$type] : array();
-}
-
-/**
- * Retrieve the basic default properties that are common to all elements.
- */
-function element_basic_defaults() {
-  return array(
-    '#description' => '',
-    '#title' => '',
-    '#attributes' => array(),
-    '#required' => FALSE,
-    '#attached' => array(),
-  );
+  return isset($cache[$type]) ? $cache[$type] : $cache['defaults'];
 }
 
 /**
diff --git modules/image/image.admin.inc modules/image/image.admin.inc
index 4207d4f..8549bf3 100644
--- modules/image/image.admin.inc
+++ modules/image/image.admin.inc
@@ -818,7 +818,7 @@ function theme_image_anchor($variables) {
   $row = array();
   foreach (element_children($element) as $n => $key) {
     $element[$key]['#attributes']['title'] = $element[$key]['#title'];
-    unset($element[$key]['#title']);
+    $element[$key]['#title'] = '';
     $row[] = drupal_render($element[$key]);
     if ($n % 3 == 3 - 1) {
       $rows[] = $row;
diff --git modules/simpletest/simpletest.pages.inc modules/simpletest/simpletest.pages.inc
index 18dbfba..33ac01d 100644
--- modules/simpletest/simpletest.pages.inc
+++ modules/simpletest/simpletest.pages.inc
@@ -139,7 +139,7 @@ function theme_simpletest_test_table($variables) {
       $title = $test['#title'];
       $description = $test['#description'];
 
-      unset($test['#title']);
+      $test['#title'] = '';
       unset($test['#description']);
 
       // Test name is used to determine what tests to run.
diff --git modules/system/system.admin.inc modules/system/system.admin.inc
index 3d722f2..4a09dac 100644
--- modules/system/system.admin.inc
+++ modules/system/system.admin.inc
@@ -2310,7 +2310,7 @@ function theme_system_modules_fieldset($variables) {
     // Stick it into $module for easier accessing.
     $module = $form[$key];
     $row = array();
-    unset($module['enable']['#title']);
+    $module['enable']['#title'] = '';
     $row[] = array('class' => array('checkbox'), 'data' => drupal_render($module['enable']));
     $label = '<label';
     if (isset($module['enable']['#id'])) {
