Index: modules/block/block.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.admin.inc,v
retrieving revision 1.60
diff -u -r1.60 block.admin.inc
--- modules/block/block.admin.inc	16 Oct 2009 23:48:37 -0000	1.60
+++ modules/block/block.admin.inc	24 Oct 2009 00:58:44 -0000
@@ -444,9 +444,9 @@
 function block_add_block_form_submit($form, &$form_state) {
   $delta = db_insert('block_custom')
     ->fields(array(
-      'body' => $form_state['values']['body'],
+      'body' => $form_state['values']['body']['value'],
       'info' => $form_state['values']['info'],
-      'format' => $form_state['values']['body_format'],
+      'format' => $form_state['values']['body']['format'],
     ))
     ->execute();
 
Index: modules/block/block.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.module,v
retrieving revision 1.394
diff -u -r1.394 block.module
--- modules/block/block.module	23 Oct 2009 22:24:11 -0000	1.394
+++ modules/block/block.module	24 Oct 2009 00:58:45 -0000
@@ -186,7 +186,7 @@
  * Implement hook_block_configure().
  */
 function block_block_configure($delta = 0) {
-  $custom_block = array('format' => filter_default_format());
+  $custom_block = array('format' => filter_format_default());
   if ($delta) {
     $custom_block = block_custom_block_get($delta);
   }
@@ -423,10 +423,10 @@
   );
   $form['body_field']['#weight'] = -17;
   $form['body_field']['body'] = array(
-    '#type' => 'textarea',
+    '#type' => 'textarea_format',
     '#title' => t('Block body'),
     '#default_value' => $edit['body'],
-    '#text_format' => isset($edit['format']) ? $edit['format'] : filter_default_format(),
+    '#format' => isset($edit['format']) ? $edit['format'] : NULL,
     '#rows' => 15,
     '#description' => t('The content of the block as shown to the user.'),
     '#required' => TRUE,
@@ -453,9 +453,9 @@
 function block_custom_block_save($edit, $delta) {
   db_update('block_custom')
     ->fields(array(
-      'body' => $edit['body'],
+      'body' => $edit['body']['value'],
       'info' => $edit['info'],
-      'format' => $edit['body_format'],
+      'format' => $edit['body']['format'],
     ))
     ->condition('bid', $delta)
     ->execute();
Index: modules/field/field.form.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.form.inc,v
retrieving revision 1.29
diff -u -r1.29 field.form.inc
--- modules/field/field.form.inc	15 Oct 2009 12:44:34 -0000	1.29
+++ modules/field/field.form.inc	24 Oct 2009 00:58:47 -0000
@@ -57,18 +57,18 @@
     $delta = isset($get_delta) ? $get_delta : 0;
     $function = $instance['widget']['module'] . '_field_widget';
     if (function_exists($function)) {
-      if ($element = $function($form, $form_state, $field, $instance, $langcode, $items, $delta)) {
-        $defaults = array(
-          '#required' => $get_delta > 0 ? FALSE : $instance['required'],
-          '#columns'  => array_keys($field['columns']),
-          '#title' => check_plain(t($instance['label'])),
-          '#description' => field_filter_xss($instance['description']),
-          '#delta' => $delta,
-          '#field_name' => $field['field_name'],
-          '#bundle' => $instance['bundle'],
-          '#object_type' => $instance['object_type'],
-        );
-        $element = array_merge($element, $defaults);
+      $base = array(
+        '#title' => check_plain(t($instance['label'])),
+        '#description' => field_filter_xss($instance['description']),
+        '#required' => $get_delta > 0 ? FALSE : $instance['required'],
+        // @todo do we need those ?
+        // '#columns'  => array_keys($field['columns']),
+        // '#field_name' => $field['field_name'],
+        // '#object_type' => $instance['object_type'],
+        // '#bundle' => $instance['bundle'],
+      );
+
+      if ($element = $function($form, $form_state, $field, $instance, $langcode, $items, $delta, $base)) {
         // If we're processing a specific delta value for a field where the
         // field module handles multiples, set the delta in the result.
         // For fields that handle their own processing, we can't make assumptions
@@ -158,23 +158,23 @@
   $function = $instance['widget']['module'] . '_field_widget';
   if (function_exists($function)) {
     for ($delta = 0; $delta <= $max; $delta++) {
-      if ($element = $function($form, $form_state, $field, $instance, $langcode, $items, $delta)) {
-        $multiple = $field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED;
-        $defaults = array(
-          // For multiple fields, title and description are handled by the wrapping table.
-          '#title' => $multiple ? '' : $title,
-          '#description' => $multiple ? '' : $description,
-          '#required' => $delta == 0 && $instance['required'],
-          '#weight' => $delta,
-          '#delta' => $delta,
-          '#columns' => array_keys($field['columns']),
-          '#field_name' => $field_name,
-          '#object_type' => $instance['object_type'],
-          '#bundle' => $instance['bundle'],
-        );
-
+      $multiple = $field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED;
+      $base = array(
+        // For multiple fields, title and description are handled by the wrapping table.
+        '#title' => $multiple ? '' : $title,
+        '#description' => $multiple ? '' : $description,
+        // Only the first widget should be required.
+        '#required' => $delta == 0 && $instance['required'],
+        // @todo do we need those ?
+        // '#columns' => array_keys($field['columns']),
+        // '#field_name' => $field_name,
+        // '#object_type' => $instance['object_type'],
+        // '#bundle' => $instance['bundle'],
+      );
+      if ($element = $function($form, $form_state, $field, $instance, $langcode, $items, $delta, $base)) {
         // Input field for the delta (drag-n-drop reordering).
         if ($multiple) {
+          $element['#weight'] = $delta;
           // We name the element '_weight' to avoid clashing with elements
           // defined by widget.
           $element['_weight'] = array(
@@ -186,7 +186,7 @@
           );
         }
 
-        $form_element[$delta] = array_merge($element, $defaults);
+        $form_element[$delta] = $element;
       }
     }
 
Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.386
diff -u -r1.386 form.inc
--- includes/form.inc	16 Oct 2009 19:20:34 -0000	1.386
+++ includes/form.inc	24 Oct 2009 00:58:44 -0000
@@ -1985,110 +1985,6 @@
 }
 
 /**
- * Add text format selector to text elements with the #text_format property.
- *
- * The #text_format property should be the ID of an text format, found in
- * {filter_format}.format, which gets passed to filter_form().
- *
- * If the property #text_format is set, the form element will be expanded into
- * two separate form elements, one holding the content of the element, and the
- * other holding the text format selector. The original element is shifted into
- * a child element, but is otherwise unaltered, so that the format selector is
- * at the same level as the text field which it affects.
- *
- * For example:
- * @code
- *   // A simple textarea, such as a node body.
- *   $form['body'] = array(
- *     '#type' => 'textarea',
- *     '#title' => t('Body'),
- *     '#text_format' => isset($node->format) ? $node->format : filter_default_format(),
- *   );
- * @endcode
- *
- * Becomes:
- * @code
- *   $form['body'] = array(
- *     // Type switches to 'markup', as we're only interested in submitting the child elements.
- *     '#type' => 'markup',
- *     // 'value' holds the original element.
- *     'value' => array(
- *       '#type' => 'textarea',
- *       '#title' => t('Body'),
- *       '#parents' => array('body'),
- *     ),
- *     // 'format' holds the text format selector.
- *     'format' => array(
- *       '#parents' => array('body_format'),
- *       ...
- *     ),
- *   );
- * @endcode
- *
- * And would result in:
- * @code
- *   // Original, unaltered form element value.
- *   $form_state['values']['body'] = 'Example content';
- *   // Chosen text format.
- *   $form_state['values']['body_format'] = 1;
- * @endcode
- *
- * @see system_element_info(), filter_form()
- */
-function form_process_text_format($element) {
-  if (isset($element['#text_format'])) {
-    // Determine the form element parents and element name to use for the input
-    // format widget. This simulates the 'element' and 'element_format' pair of
-    // parents that filter_form() expects.
-    $element_parents = $element['#parents'];
-    $element_name = array_pop($element_parents);
-    $element_parents[] = $element_name . '_format';
-
-    // We need to break references, otherwise form_builder recurses infinitely.
-    $element['value'] = (array)$element;
-    $element['value']['#weight'] = 0;
-    unset($element['value']['#description']);
-    $element['#type'] = 'markup';
-    $element['#theme'] = NULL;
-    $element['#theme_wrappers'] = array('text_format_wrapper');
-    $element['format'] = filter_form($element['#text_format'], 1, $element_parents);
-
-    // We need to clear the #text_format from the new child otherwise we
-    // would get into an infinite loop.
-    unset($element['value']['#text_format']);
-  }
-  return $element;
-}
-
-/**
- * Theme a text format form element.
- *
- * @param $variables
- *   An associative array containing:
- *   - element: An associative array containing the properties of the element.
- *     Properties used: #children, #description
- *
- * @return
- *   A string representing the form element.
- *
- * @ingroup themeable
- */
-function theme_text_format_wrapper($variables) {
-  $element = $variables['element'];
-  $output = '<div class="text-format-wrapper">' . "\n";
-
-  $output .= $element['#children'] . "\n";
-
-  if (!empty($element['#description'])) {
-    $output .= '<div class="description">' . $element['#description'] . "</div>\n";
-  }
-
-  $output .= "</div>\n";
-
-  return $output;
-}
-
-/**
  * Theme a checkbox form element.
  *
  * @param $variables
Index: modules/field/modules/text/text.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/text/text.module,v
retrieving revision 1.34
diff -u -r1.34 text.module
--- modules/field/modules/text/text.module	23 Oct 2009 22:24:13 -0000	1.34
+++ modules/field/modules/text/text.module	24 Oct 2009 00:58:50 -0000
@@ -146,7 +146,7 @@
     '#default_value' => $settings['text_processing'],
     '#options' => array(
       t('Plain text'),
-      t('Filtered text (user selects input format)'),
+      t('Filtered text (user selects text format)'),
     ),
   );
   if ($field['type'] == 'text_with_summary') {
@@ -154,7 +154,7 @@
       '#type' => 'checkbox',
       '#title' => t('Summary input'),
       '#default_value' => $settings['display_summary'],
-      '#description' => t('This allows authors to input an explicit summary, to be displayed instead of the automatically trimmed text when using the "Summary or trimmed" display format.'),
+      '#description' => t('This allows authors to input an explicit summary, to be displayed instead of the automatically trimmed text when using the "Summary or trimmed" display type.'),
     );
   }
 
@@ -170,13 +170,16 @@
  */
 function text_field_validate($obj_type, $object, $field, $instance, $langcode, $items, &$errors) {
   foreach ($items as $delta => $item) {
-    foreach (array('value' => t('full text'), 'summary' => t('summary')) as $column => $desc) {
+    // @todo Length is counted separately for summary and value, so the maximum
+    //   length can be exceeded very easily.
+    foreach (array('value', 'summary') as $column) {
       if (!empty($item[$column])) {
         if (!empty($field['settings']['max_length']) && drupal_strlen($item[$column]) > $field['settings']['max_length']) {
           switch ($column) {
             case 'value':
               $message = t('%name: the text may not be longer than %max characters.', array('%name' => $instance['label'], '%max' => $field['settings']['max_length']));
               break;
+
             case 'summary':
               $message = t('%name: the summary may not be longer than %max characters.', array('%name' => $instance['label'], '%max' => $field['settings']['max_length']));
               break;
@@ -205,11 +208,11 @@
       if (!empty($instances[$id]['settings']['text_processing'])) {
         // Only process items with a cacheable format, the rest will be
         // handled by text_field_sanitize().
-        $format = $item['format'];
-        if (filter_format_allowcache($format)) {
-          $items[$id][$delta]['safe'] = isset($item['value']) ? check_markup($item['value'], $format, $langcode) : '';
+        $format_id = $item['format'];
+        if (filter_format_allowcache($format_id)) {
+          $items[$id][$delta]['safe'] = isset($item['value']) ? check_markup($item['value'], $format_id, $langcode) : '';
           if ($field['type'] == 'text_with_summary') {
-            $items[$id][$delta]['safe_summary'] = isset($item['summary']) ? check_markup($item['summary'], $format, $langcode) : '';
+            $items[$id][$delta]['safe_summary'] = isset($item['summary']) ? check_markup($item['summary'], $format_id, $langcode) : '';
           }
         }
       }
@@ -235,10 +238,10 @@
     // from a form preview.
     if (!isset($items[$delta]['safe'])) {
       if (!empty($instance['settings']['text_processing'])) {
-        $format = $item['format'];
-        $items[$delta]['safe'] = isset($item['value']) ? check_markup($item['value'], $format, $langcode, TRUE) : '';
+        $format_id = $item['format'];
+        $items[$delta]['safe'] = isset($item['value']) ? check_markup($item['value'], $format_id, $langcode, TRUE) : '';
         if ($field['type'] == 'text_with_summary') {
-          $items[$delta]['safe_summary'] = isset($item['summary']) ? check_markup($item['summary'], $format, $langcode, TRUE) : '';
+          $items[$delta]['safe_summary'] = isset($item['summary']) ? check_markup($item['summary'], $format_id, $langcode, TRUE) : '';
         }
       }
       else {
@@ -469,14 +472,6 @@
 
 /**
  * Implement hook_field_widget_info().
- *
- * Here we indicate that the field module will handle
- * the default value and multiple values for these widgets.
- *
- * Callbacks can be omitted if default handing is used.
- * They're included here just so this module can be used
- * as an example for custom modules that might do things
- * differently.
  */
 function text_field_widget_info() {
   return array(
@@ -528,268 +523,78 @@
 }
 
 /**
- * Implement hook_element_info().
- *
- * Autocomplete_path is not used by text_field_widget but other
- * widgets can use it (see nodereference and userreference).
- */
-function text_element_info() {
-  $types['text_textfield'] = array(
-    '#input' => TRUE,
-    '#columns' => array('value'),
-    '#delta' => 0,
-    '#process' => array('text_textfield_elements_process'),
-    '#theme_wrappers' => array('text_textfield'),
-    '#autocomplete_path' => FALSE,
-  );
-  $types['text_textarea'] = array(
-    '#input' => TRUE,
-    '#columns' => array('value', 'format'),
-    '#delta' => 0,
-    '#process' => array('text_textarea_elements_process'),
-    '#theme_wrappers' => array('text_textarea'),
-    '#filter_value' => filter_default_format(),
-  );
-  $types['text_textarea_with_summary'] = array(
-    '#input' => TRUE,
-    '#columns' => array('value', 'format', 'summary'),
-    '#delta' => 0,
-    '#process' => array('text_textarea_with_summary_process'),
-    '#theme_wrappers' => array('text_textarea'),
-    '#filter_value' => filter_default_format(),
-  );
-  return $types;
-}
-
-/**
  * Implement hook_field_widget().
- *
- * Attach a single form element to the form. It will be built out and
- * validated in the callback(s) listed in hook_element_info(). We build it
- * out in the callbacks rather than here in hook_field_widget so it can be
- * plugged into any module that can provide it with valid
- * $field information.
- *
- * Field module will set the weight, field name and delta values
- * for each form element.
- *
- * If there are multiple values for this field, the field module will
- * call this function as many times as needed.
- *
- * @param $form
- *   the entire form array, $form['#node'] holds node information
- * @param $form_state
- *   the form_state, $form_state['values'][$field['field_name']]
- *   holds the field's form values.
- * @param $field
- *   The field structure.
- * @param $instance
- *   the field instance array
- * @param $langcode
- *   The language associated to $items.
- * @param $items
- *   array of default values for this field
- * @param $delta
- *   the order of this item in the array of subelements (0, 1, 2, etc)
- *
- * @return
- *   the form item for a single element for this field
  */
-function text_field_widget(&$form, &$form_state, $field, $instance, $langcode, $items, $delta = 0) {
-  $element = array(
-    '#type' => $instance['widget']['type'],
-    '#default_value' => isset($items[$delta]) ? $items[$delta] : '',
-  );
-  if (!empty($instance['settings']['text_processing'])) {
-    $element['#value_callback'] = 'text_field_widget_formatted_text_value';
-  }
+function text_field_widget(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $base) {
+  $columns = array_keys($field['columns']);
 
-  return $element;
-}
+  // @todo : let single-value widgets receive the $item directly ?
+  $item = isset($items[$delta]) ? $items[$delta] : array();
 
-/**
- * Implement hook_field_widget_error().
- */
-function text_field_widget_error($element, $error) {
-  switch ($error['error']) {
-    case 'text_summary_max_length':
-      $error_element = $element[$element['#columns'][1]];
+  if (isset($columns[1]) && $columns[1] == 'summary') {
+    $display = !empty($item['summary']) || !empty($instance['settings']['display_summary']);
+    $element['summary'] = array(
+      '#title' => t('Summary'),
+      '#type' => $display ? 'textarea' : 'value',
+      '#default_value' => isset($item['summary']) ? $item['summary'] : NULL,
+      '#rows' => $instance['widget']['settings']['summary_rows'],
+      '#title' => t('Summary'),
+      '#description' => t('Leave blank to use trimmed value of full text as the summary.'),
+      '#attached' => array('js' => array(drupal_get_path('module', 'text') . '/text.js')),
+      '#attributes' => array('class' => array('text-summary')),
+      '#prefix' => '<div class="text-summary-wrapper">',
+      '#suffix' => '</div>',
+    );
+  }
+
+  switch ($instance['widget']['type']) {
+    case 'text_textfield':
+      $element['value'] = array(
+        '#type' => 'textfield',
+        '#default_value' => isset($item['value']) ? $item['value'] : NULL,
+        '#size' => $instance['widget']['settings']['size'],
+        '#attributes' => array('class' => array('text-textfield')),
+      ) + $base;
       break;
 
     default:
-      $error_element = $element[$element['#columns'][0]];
+      $element['value'] = array(
+        '#type' => 'textarea',
+        '#default_value' => isset($item['value']) ? $item['value'] : NULL,
+        '#rows' => $instance['widget']['settings']['rows'],
+        '#attributes' => array('class' => array('text-textarea')),
+        '#prefix' => '<div class="text-full-wrapper">',
+        '#suffix' => '</div>',
+      ) + $base;
       break;
   }
 
-  form_error($error_element, $error['message']);
-}
-
-/**
- * Process an individual element.
- *
- * Build the form element. When creating a form using FAPI #process,
- * note that $element['#value'] is already set.
- *
- * The $field and $instance arrays are in $form['#fields'][$element['#field_name']].
- *
- * TODO: For widgets to be actual FAPI 'elements', reusable outside of a
- * 'field' context, they shoudn't rely on $field and $instance. The bits of
- * information needed to adjust the behavior of the 'element' should be
- * extracted in hook_field_widget() above.
- */
-function text_textfield_elements_process($element, $form_state, $form) {
-  $field = $form['#fields'][$element['#field_name']]['field'];
-  $instance = $form['#fields'][$element['#field_name']]['instance'];
-  $field_key = $element['#columns'][0];
-  $delta = $element['#delta'];
-
-  $element[$field_key] = array(
-    '#type' => 'textfield',
-    '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
-    '#autocomplete_path' => $element['#autocomplete_path'],
-    '#size' => $instance['widget']['settings']['size'],
-    '#attributes' => array('class' => array('text')),
-    '#title' => $element['#title'],
-    '#description' => $element['#description'],
-    '#required' => $element['#required'],
-  );
-
-  $element[$field_key]['#maxlength'] = !empty($field['settings']['max_length']) ? $field['settings']['max_length'] : NULL;
-
+  // Conditionally alter the form element's type if text processing is enabled.
   if (!empty($instance['settings']['text_processing'])) {
-    $filter_key  = (count($element['#columns']) == 2) ? $element['#columns'][1] : 'format';
-    $format = isset($element['#value'][$filter_key]) ? $element['#value'][$filter_key] : filter_default_format();
-    $element[$field_key]['#text_format'] = $format;
+    $element['value']['#type'] .= '_format';
+    $element['value']['#format'] = isset($item['format']) ? $item['format'] : NULL;
+    // Signal filter_process_form() to not expand the form element into 'value'
+    // and 'format', since we need all submitted form values on one level.
+    $element['value']['#format_tree'] = FALSE;
   }
 
   return $element;
 }
 
 /**
- * Process an individual element.
- *
- * Build the form element. When creating a form using FAPI #process,
- * note that $element['#value'] is already set.
- *
- * The $field and $instance arrays are in $form['#fields'][$element['#field_name']].
- */
-function text_textarea_elements_process($element, $form_state, $form) {
-  $field = $form['#fields'][$element['#field_name']]['field'];
-  $instance = $form['#fields'][$element['#field_name']]['instance'];
-  $field_key = $element['#columns'][0];
-  $delta = $element['#delta'];
-
-  $element[$field_key] = array(
-    '#type' => 'textarea',
-    '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
-    '#rows' => $instance['widget']['settings']['rows'],
-    '#weight' => 0,
-    '#title' => $element['#title'],
-    '#description' => $element['#description'],
-    '#required' => $element['#required'],
-  );
-
-  if (!empty($instance['settings']['text_processing'])) {
-    $filter_key = (count($element['#columns']) == 2) ? $element['#columns'][1] : 'format';
-    $format = isset($element['#value'][$filter_key]) ? $element['#value'][$filter_key] : filter_default_format();
-    $element[$field_key]['#text_format'] = $format;
-  }
-
-  return $element;
-}
-
-/**
- * Process an individual element.
- *
- * Build the form element. When creating a form using FAPI #process,
- * note that $element['#value'] is already set.
- *
- * The $field and $instance arrays are in $form['#fields'][$element['#field_name']].
+ * Implement hook_field_widget_error().
  */
-function text_textarea_with_summary_process($element, $form_state, $form) {
-  $field = $form['#fields'][$element['#field_name']]['field'];
-  $instance = $form['#fields'][$element['#field_name']]['instance'];
-  $delta = $element['#delta'];
-
-  $field_key = $element['#columns'][1];
-  $display = !empty($element['#value'][$field_key]) || !empty($instance['settings']['display_summary']);
-  $element[$field_key] = array(
-    '#title' => t('Summary'),
-    '#type' => $display ? 'textarea' : 'value',
-    '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
-    '#rows' => $instance['widget']['settings']['summary_rows'],
-    '#weight' => 0,
-    '#title' => t('Summary'),
-    '#description' => t('Leave blank to use trimmed value of full text as the summary.'),
-    '#required' => $element['#required'],
-    '#display' => $display,
-    '#attached' => array('js' => array(drupal_get_path('module', 'text') . '/text.js')),
-    '#attributes' => array('class' => array('text-textarea-summary')),
-    '#prefix' => '<div class="text-summary-wrapper">',
-    '#suffix' => '</div>',
-  );
-
-  $field_key = $element['#columns'][0];
-  $element[$field_key] = array(
-    '#type' => 'textarea',
-    '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
-    '#rows' => $instance['widget']['settings']['rows'],
-    '#weight' => 1,
-    '#title' => $display ? t('Full text') : $element['#title'],
-    '#description' => $element['#description'],
-    '#required' => $element['#required'],
-    '#required' => $instance['required'],
-    '#attributes' => array('class' => array('text-full-textarea')),
-    '#prefix' => '<div class="text-full-wrapper">',
-    '#suffix' => '</div>',
-  );
-
-  if (!empty($instance['settings']['text_processing'])) {
-    $filter_key  = (count($element['#columns']) == 2) ? $element['#columns'][1] : 'format';
-    $format = isset($element['#value'][$filter_key]) ? $element['#value'][$filter_key] : filter_default_format();
-    $element[$field_key]['#text_format'] = $format;
-  }
-
-  return $element;
-}
+function text_field_widget_error($element, $error) {
+  switch ($error['error']) {
+    case 'text_summary_max_length':
+      $error_element = $element['summary'];
+      break;
 
-/**
- * Helper function to determine the value for a formatted text widget.
- *
- * '#text_format' puts the format in '[column 0]_format' in incoming values,
- * while we need it in '[column 1]'.
- */
-function text_field_widget_formatted_text_value($form, $edit = FALSE) {
-  if ($edit !== FALSE) {
-    $field_key = $form['#columns'][0];
-    $filter_key = (count($form['#columns']) == 2) ? $form['#columns'][1] : 'format';
-    $default_key = $field_key . '_format';
-    // The format selector uses #access = FALSE if only one format is
-    // available. In this case, we don't receive its value, and need to
-    // manually set it.
-    $edit['format'] = !empty($edit[$default_key]) ? $edit[$default_key] : filter_default_format();
-    unset($edit[$default_key]);
-    return $edit;
+    default:
+      $error_element = $element['value'];
+      break;
   }
-}
 
-/**
- * FAPI theme for an individual text elements.
- *
- * The textfield or textarea is already rendered by the
- * textfield or textarea themes and the html output
- * lives in $variables['element']['#children']. Override this theme to
- * make custom changes to the output.
- *
- * $variables['element']['#field_name'] contains the field name
- * $variables['element']['#delta] is the position of this element in the group
- */
-function theme_text_textfield($variables) {
-  $element = $variables['element'];
-  return $element['#children'];
+  form_error($element[$field_key], $error['message']);
 }
 
-function theme_text_textarea($variables) {
-  $element = $variables['element'];
-  return $element['#children'];
-}
Index: modules/field/modules/text/text.js
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/text/text.js,v
retrieving revision 1.1
diff -u -r1.1 text.js
--- modules/field/modules/text/text.js	11 Sep 2009 13:30:49 -0000	1.1
+++ modules/field/modules/text/text.js	24 Oct 2009 00:58:49 -0000
@@ -5,9 +5,9 @@
 /**
  * Auto-hide summary textarea if empty and show hide and unhide links.
  */
-Drupal.behaviors.textTextareaSummary = {
+Drupal.behaviors.textSummary = {
   attach: function (context, settings) {
-    $('textarea.text-textarea-summary:not(.text-textarea-summary-processed)', context).addClass('text-textarea-summary-processed').each(function () {
+    $('textarea.text-summary', context).once('text-summary', function () {
       var $fieldset = $(this).closest('#body-wrapper');
       var $summary = $fieldset.find('div.text-summary-wrapper');
       var $summaryLabel = $summary.find('div.form-type-textarea label');
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.824
diff -u -r1.824 system.module
--- modules/system/system.module	23 Oct 2009 22:24:18 -0000	1.824
+++ modules/system/system.module	24 Oct 2009 00:58:57 -0000
@@ -372,7 +372,7 @@
     '#size' => 60,
     '#maxlength' => 128,
     '#autocomplete_path' => FALSE,
-    '#process' => array('form_process_text_format', 'ajax_process_form'),
+    '#process' => array('ajax_process_form'),
     '#theme' => 'textfield',
     '#theme_wrappers' => array('form_element'),
   );
@@ -394,7 +394,7 @@
     '#cols' => 60,
     '#rows' => 5,
     '#resizable' => TRUE,
-    '#process' => array('form_process_text_format', 'ajax_process_form'),
+    '#process' => array('ajax_process_form'),
     '#theme' => 'textarea',
     '#theme_wrappers' => array('form_element'),
   );
Index: modules/profile/profile.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/profile/profile.module,v
retrieving revision 1.280
diff -u -r1.280 profile.module
--- modules/profile/profile.module	23 Oct 2009 22:24:16 -0000	1.280
+++ modules/profile/profile.module	24 Oct 2009 00:58:53 -0000
@@ -280,7 +280,7 @@
   if (isset($account->{$field->name}) && $value = $account->{$field->name}) {
     switch ($field->type) {
       case 'textarea':
-        return check_markup($value, filter_default_format($account), '', TRUE);
+        return check_markup($value, filter_format_default($account), '', TRUE);
       case 'textfield':
       case 'selection':
         return $browse ? l($value, 'profile/' . $field->name . '/' . $value) : check_plain($value);
Index: modules/filter/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v
retrieving revision 1.300
diff -u -r1.300 filter.module
--- modules/filter/filter.module	23 Oct 2009 22:24:14 -0000	1.300
+++ modules/filter/filter.module	24 Oct 2009 00:58:51 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: filter.module,v 1.300 2009/10/23 22:24:14 webchick Exp $
+// $Id: filter.module,v 1.299 2009/10/23 01:06:58 dries Exp $
 
 /**
  * @file
@@ -49,16 +49,38 @@
       'variables' => array('tips' => NULL, 'long' => FALSE),
       'file' => 'filter.pages.inc',
     ),
+    'filter_format_wrapper' => array(
+      'render_element' => array('element' => array()),
+    ),
     'filter_tips_more_info' => array(
       'variables' => array(),
     ),
     'filter_guidelines' => array(
-      'variables' => array('format' => NULL),
+      // @see http://drupal.org/node/600974
+      'variables' => array('format' => NULL, 'dummy' => NULL),
     ),
   );
 }
 
 /**
+ * Implement of hook_elements().
+ *
+ * Elements defined by Filter module are wrappers around the respective,
+ * non-prefixed elements and are expanded by filter_process_format().
+ *
+ * @see filter_process_format()
+ */
+function filter_element_info() {
+  $type['textfield_format'] = array(
+    '#process' => array('filter_process_format'),
+  );
+  $type['textarea_format'] = array(
+    '#process' => array('filter_process_format'),
+  );
+  return $type;
+}
+
+/**
  * Implement hook_menu().
  */
 function filter_menu() {
@@ -428,7 +450,7 @@
  *
  * @see filter_fallback_format()
  */
-function filter_default_format($account = NULL) {
+function filter_format_default($account = NULL) {
   global $user;
   if (!isset($account)) {
     $account = $user;
Index: modules/filter/filter.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.test,v
retrieving revision 1.46
diff -u -r1.46 filter.test
--- modules/filter/filter.test	13 Oct 2009 15:39:41 -0000	1.46
+++ modules/filter/filter.test	24 Oct 2009 00:58:52 -0000
@@ -496,8 +496,8 @@
 
     // Check that each user's default format is the lowest weighted format that
     // the user has access to.
-    $this->assertEqual(filter_default_format($first_user), $first_format->format, t("The first user's default format is the lowest weighted format that the user has access to."));
-    $this->assertEqual(filter_default_format($second_user), $second_format->format, t("The second user's default format is the lowest weighted format that the user has access to, and is different than the first user's."));
+    $this->assertEqual(filter_format_default($first_user), $first_format->format, t("The first user's default format is the lowest weighted format that the user has access to."));
+    $this->assertEqual(filter_format_default($second_user), $second_format->format, t("The second user's default format is the lowest weighted format that the user has access to, and is different than the first user's."));
 
     // Reorder the two formats, and check that both users now have the same
     // default.
@@ -505,7 +505,7 @@
     $edit['formats[' . $second_format->format . '][weight]'] = $minimum_weight - 3;
     $this->drupalPost('admin/config/content/formats', $edit, t('Save changes'));
     $this->resetFilterCaches();
-    $this->assertEqual(filter_default_format($first_user), filter_default_format($second_user), t('After the formats are reordered, both users have the same default format.'));
+    $this->assertEqual(filter_format_default($first_user), filter_format_default($second_user), t('After the formats are reordered, both users have the same default format.'));
   }
 
   /**
Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.165
diff -u -r1.165 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	22 Oct 2009 01:09:05 -0000	1.165
+++ modules/simpletest/drupal_web_test_case.php	24 Oct 2009 00:58:55 -0000
@@ -728,7 +728,7 @@
     // Merge body field value and format separately.
     $body = array(
       'value' => $this->randomName(32),
-      'format' => filter_default_format(),
+      'format' => filter_format_default(),
     );
     $langcode = !empty($settings['language']) ? $settings['language'] : FIELD_LANGUAGE_NONE;
     $settings['body'][$langcode][0] += $body;
Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.796
diff -u -r1.796 comment.module
--- modules/comment/comment.module	23 Oct 2009 22:24:12 -0000	1.796
+++ modules/comment/comment.module	24 Oct 2009 00:58:46 -0000
@@ -1293,7 +1293,7 @@
         'changed' => $comment->changed,
         'subject' => $comment->subject,
         'comment' => $comment->comment,
-        'format' => $comment->comment_format,
+        'format' => $comment->format,
         'uid' => $comment->uid,
         'name' => $comment->name,
         'mail' => $comment->mail,
@@ -1369,7 +1369,7 @@
         'uid' => $comment->uid,
         'subject' => $comment->subject,
         'comment' => $comment->comment,
-        'format' => $comment->comment_format,
+        'format' => $comment->format,
         'hostname' => ip_address(),
         'created' => $comment->created,
         'changed' => $comment->changed,
@@ -1846,11 +1846,11 @@
   }
 
   $form['comment'] = array(
-    '#type' => 'textarea',
+    '#type' => 'textarea_format',
     '#title' => t('Comment'),
     '#rows' => 15,
     '#default_value' => $default,
-    '#text_format' => isset($comment->format) ? $comment->format : filter_default_format(),
+    '#format' => isset($comment->format) ? $comment->format : NULL,
     '#required' => TRUE,
   );
 
@@ -1928,7 +1928,8 @@
   $node = node_load($comment->nid);
 
   if (!form_get_errors()) {
-    $comment->format = $comment->comment_format;
+    $comment->format = $comment->comment['format'];
+    $comment->comment = $comment->comment['value'];
 
     // Attach the user and time information.
     if (!empty($comment->author)) {
@@ -2058,7 +2059,7 @@
     // 1) Filter it into HTML
     // 2) Strip out all HTML tags
     // 3) Convert entities back to plain-text.
-    $comment['subject'] = truncate_utf8(trim(decode_entities(strip_tags(check_markup($comment['comment'], $comment['comment_format'])))), 29, TRUE);
+    $comment['subject'] = truncate_utf8(trim(decode_entities(strip_tags(check_markup($comment['comment']['value'], $comment['comment']['format'])))), 29, TRUE);
     // Edge cases where the comment body is populated only by HTML tags will
     // require a default subject.
     if ($comment['subject'] == '') {
