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 -p -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	21 Nov 2009 22:51:12 -0000
@@ -5,13 +5,13 @@
 /**
  * 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 () {
-      var $fieldset = $(this).closest('#body-wrapper');
-      var $summary = $fieldset.find('div.text-summary-wrapper');
-      var $summaryLabel = $summary.find('div.form-type-textarea label');
-      var $full = $fieldset.find('div.text-full-wrapper');
+    $('.text-summary', context).once('text-summary', function () {
+      var $widget = $(this).closest('div.field-type-text-with-summary');
+      var $summary = $widget.find('div.text-summary-wrapper');
+      var $summaryLabel = $summary.find('label');
+      var $full = $widget.find('div.text-full-wrapper');
       var $fullLabel = $full.find('div.form-type-textarea label');
 
       // Setup the edit/hide summary link.
Index: modules/field/modules/text/text.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/text/text.module,v
retrieving revision 1.36
diff -u -p -r1.36 text.module
--- modules/field/modules/text/text.module	11 Nov 2009 08:32:35 -0000	1.36
+++ modules/field/modules/text/text.module	22 Nov 2009 00:14:21 -0000
@@ -7,20 +7,6 @@
  */
 
 /**
- * Implement hook_theme().
- */
-function text_theme() {
-  return array(
-    'text_textarea' => array(
-      'render element' => 'element',
-    ),
-    'text_textfield' => array(
-      'render element' => 'element',
-    ),
-  );
-}
-
-/**
  * Implement hook_field_info().
  *
  * Field settings:
@@ -146,7 +132,7 @@ function text_field_instance_settings_fo
     '#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 +140,7 @@ function text_field_instance_settings_fo
       '#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 +156,16 @@ function text_field_instance_settings_fo
  */
 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 +194,11 @@ function text_field_load($obj_type, $obj
       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 +224,10 @@ function text_field_sanitize($obj_type, 
     // 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 +458,6 @@ function text_summary($text, $format = N
 
 /**
  * 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,48 +509,56 @@ function text_field_widget_settings_form
 }
 
 /**
- * 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().
  */
-function text_field_widget(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
-  $element += array(
-    '#type' => $instance['widget']['type'],
-    '#default_value' => isset($items[$delta]) ? $items[$delta] : '',
-  );
+function text_field_widget(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $base) {
+  $element = $base;
+
+  // Add the Summary field as separate form element, if enabled.
+  if (isset($base['#columns'][1]) && $base['#columns'][1] == 'summary') {
+    $field_key = $base['#columns'][1];
+    $display = !empty($items[$delta][$field_key]) || !empty($instance['settings']['display_summary']);
+    $element[$field_key] = array(
+      '#type' => $display ? 'textarea' : 'value',
+      '#default_value' => isset($items[$delta][$field_key]) ? $items[$delta][$field_key] : NULL,
+      '#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>',
+      '#weight' => -10,
+    );
+  }
+
+  $field_key = $base['#columns'][0];
+  switch ($instance['widget']['type']) {
+    case 'text_textfield':
+      $element[$field_key] = $base + array(
+        '#type' => 'textfield',
+        '#default_value' => isset($items[$delta][$field_key]) ? $items[$delta][$field_key] : NULL,
+        '#size' => $instance['widget']['settings']['size'],
+        '#prefix' => '<div class="text-full-wrapper">',
+        '#suffix' => '</div>',
+      );
+      break;
+
+    default:
+      $element[$field_key] = $base + array(
+        '#type' => 'textarea',
+        '#default_value' => isset($items[$delta][$field_key]) ? $items[$delta][$field_key] : NULL,
+        '#prefix' => '<div class="text-full-wrapper">',
+        '#suffix' => '</div>',
+      );
+      break;
+  }
+
   if (!empty($instance['settings']['text_processing'])) {
+    $element[$field_key]['#text_format'] = isset($items[$delta]['format']) ? $items[$delta]['format'] : filter_default_format();
+    $element['#type'] = 'markup';
+    $element['#input'] = TRUE;
     $element['#value_callback'] = 'text_field_widget_formatted_text_value';
   }
 
@@ -594,140 +583,14 @@ function text_field_widget_error($elemen
 }
 
 /**
- * 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'],
-    '#title' => $element['#title'],
-    '#description' => $element['#description'],
-    '#required' => $element['#required'],
-  );
-
-  $element[$field_key]['#maxlength'] = !empty($field['settings']['max_length']) ? $field['settings']['max_length'] : NULL;
-
-  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']].
- */
-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']].
- */
-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.'),
-    '#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'],
-    '#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;
-}
-
-/**
  * 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) {
+function text_field_widget_formatted_text_value(&$element, $edit = FALSE, &$form_state) {
   if ($edit !== FALSE) {
-    $field_key = $form['#columns'][0];
-    $filter_key = (count($form['#columns']) == 2) ? $form['#columns'][1] : 'format';
+    $field_key = $element['#columns'][0];
     $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
@@ -738,23 +601,3 @@ function text_field_widget_formatted_tex
   }
 }
 
-/**
- * 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'];
-}
-
-function theme_text_textarea($variables) {
-  $element = $variables['element'];
-  return $element['#children'];
-}
