Index: modules/field/field.attach.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.attach.inc,v
retrieving revision 1.33
diff -u -p -r1.33 field.attach.inc
--- modules/field/field.attach.inc	16 Jul 2009 10:30:12 -0000	1.33
+++ modules/field/field.attach.inc	16 Jul 2009 23:23:29 -0000
@@ -1,5 +1,13 @@
 <?php
+<<<<<<< field.attach.inc
+<<<<<<< field.attach.inc
+// $Id: field.attach.inc,v 1.22 2009/06/07 00:00:57 webchick Exp $
+=======
+// $Id: field.attach.inc,v 1.31 2009/07/11 00:56:45 webchick Exp $
+>>>>>>> 1.31
+=======
 // $Id: field.attach.inc,v 1.33 2009/07/16 10:30:12 dries Exp $
+>>>>>>> 1.33
 
 /**
  * @file
@@ -58,14 +66,14 @@ class FieldQueryException extends FieldE
  */
 
 /**
- * Argument for an insert operation.
+ * Argument for an update operation.
  * This is used in hook_field_storage_write when updating an
  * existing object.
  */
 define('FIELD_STORAGE_UPDATE', 'update');
 
 /**
- * Argument for an update operation.
+ * Argument for an insert operation.
  * This is used in hook_field_storage_write when inserting a new object.
  */
 define('FIELD_STORAGE_INSERT', 'insert');
@@ -80,7 +88,7 @@ define('FIELD_STORAGE_INSERT', 'insert')
  * Operate on Field API data attached to Drupal objects.
  *
  * Field Attach API functions load, store, generate Form API
- * structures, display, and perform a vareity of other functions for
+ * structures, display, and perform a variety of other functions for
  * field data connected to individual objects.
  *
  * Field Attach API functions generally take $obj_type and $object
@@ -135,6 +143,7 @@ define('FIELD_STORAGE_INSERT', 'insert')
  *   - delete revision
  *   - sanitize
  *   - view
+ *   - preprocess
  *   - prepare translation
  * @param $obj_type
  *   The type of $object; e.g. 'node' or 'user'.
@@ -142,7 +151,7 @@ define('FIELD_STORAGE_INSERT', 'insert')
  *   The fully formed $obj_type object.
  * @param $a
  *   - The $form in the 'form' operation.
- *   - The value of $build_mode in the 'view' operation.
+ *   - The value of $teaser in the 'view' operation.
  *   - Otherwise NULL.
  * @param $b
  *   - The $form_state in the 'submit' operation.
@@ -353,11 +362,102 @@ function _field_invoke_multiple_default(
  *   The form structure to fill in.
  * @param $form_state
  *   An associative array containing the current state of the form.
- *
- * TODO : document the resulting $form structure, like we do for
- * field_attach_view().
- */
+ * @return
+ *   An associative array that is combined the with original form. Note that the orginial $form
+ *   is also modified inside the call to field_attach_form. It is passed in by reference.
+ *   The elements listed are the only ones either added of changed.
+ *   The $form array with a field named 'field_foo' will look like:
+ *   $form array(
+ *     '#fields' = > array(
+ *       // One sub-array where the key is the field name for each field in the bundle.
+ *       'field_foo' => array (
+ *         'field' => the field definition structure,
+ *         'instance' => the field instance definition structure,
+ *         'form_path' => 'field_name',
+ *       )
+ *     ) 
+ *     // Unless it is AHAH then TRUE.
+ *     '#cache' => FALSE
+ *     // One sub-array where the key is the field name for each field in the bundle.
+ *     'field_foo' array(
+ *       '#theme' => 'field_multiple_value_form',
+ *       // Number of field values.
+ *       '#multiple' => the field cardinality,
+ *       // Field title.
+ *       '#title' => the label of the field instance,
+ *       // Whether or not it is required.
+ *       '#required' => FALSE,
+ *       // One numbered sub-array for each field value.
+ *       // Only multiple form elements: one numbered sub-array
+ *       // for each field value.
+ *       0 => array(
+ *         '#type' => 'widget type',
+ *         '#default_value' => array(
+ *           'value' => 'value0',
+ *           'format' => null,
+ *           'safe' => 'value0',
+ *         )
+ *         // Whether or not field is required.
+ *         '#required' => TRUE,
+ *         '#columns' => array(
+ *           0 => 'value',
+ *           1 => 'format',
+ *         )
+ *         '#title' => the label of the field instance,
+ *         // Value index.
+ *         '#delta' => 0,
+ *         '#field_name' => 'field_name',
+ *         '#bundle' => $bundle,
+ *       )
+ *       1 => array(
+ *         '#type' => 'widget type',
+ *         '#default_value' => array(
+ *           'value' => 'value1',
+ *           'format' => null,
+ *           'safe' => 'value1',
+ *         )
+ *         '#title' => the label of the field instance,
+ *         // Whether or not field is required.
+ *         '#required' => TRUE,
+ *         '#weight' => weight of this value
+ *         // Value index.
+ *         '#delta' => 1,
+ *         '#columns' => array(
+ *           0 => 'value',
+ *           1 => 'format',
+ *         )
+ *         '#field_name' => 'field_name',
+ *         '#bundle' => $bundle,
+ *       )
+ *       2 => array(
+ *         '#type' => 'widget type',
+ *         '#default_value' => array(
+ *           'value' => 'value2',
+ *           'format' => null,
+ *           'safe' => 'value2',
+ *         )
+ *         // Whether or not field is required.
+ *         '#required' => TRUE,
+ *         '#columns' => array(
+ *           0 => 'value',
+ *           1 => 'format',
+ *       )
+ *       '#title' => the label of the field instance,
+ *       // Value index.
+ *       '#delta' => 2,
+ *       '#field_name' => 'field_name',
+ *       '#bundle' => $bundle,
+ *     )
+ *     '#field_name' => 'field_name',
+ *     '#tree' => TRUE,
+ *     '#weight' => 'weight',
+ *   )
+ */
+<<<<<<< field.attach.inc
+function field_attach_form($obj_type, $object, &$form, $form_state) {
+=======
 function field_attach_form($obj_type, $object, &$form, &$form_state) {
+>>>>>>> 1.31
   $form += (array) _field_invoke_default('form', $obj_type, $object, $form, $form_state);
 
   // Let other modules make changes to the form.
@@ -401,10 +501,12 @@ function field_attach_load($obj_type, $o
   // In addition, do not write to the cache when loading a single field.
   $cache_write = $cache_read && !isset($options['field_name']);
 
-  if (empty($objects)) {
-    return;
-  }
+  $queried_objects = array();
 
+<<<<<<< field.attach.inc
+  // Fetch avaliable objects from cache.
+  if ($cacheable) {
+=======
   // Assume all objects will need to be queried. Objects found in the cache
   // will be removed from the list.
   $queried_objects = $objects;
@@ -419,18 +521,25 @@ function field_attach_load($obj_type, $o
     $cache = cache_get_multiple($cids, 'cache_field');
     // Put the cached field values back into the objects and remove them from
     // the list of objects to query.
+>>>>>>> 1.33
     foreach ($objects as $id => $object) {
       $cid = "field:$obj_type:$id";
-      if (isset($cache[$cid])) {
-        unset($queried_objects[$id]);
-        foreach ($cache[$cid]->data as $field_name => $values) {
-          $object->$field_name = $values;
+      if ($cached = cache_get($cid, 'cache_field')) {
+        foreach ($cached->data as $key => $value) {
+          $object->$key = $value;
         }
       }
+      else {
+        $queried_objects[$id] = $objects[$id];
+      }
     }
   }
+  else {
+    $queried_objects = $objects;
+  }
 
-  // Fetch other objects from their storage location.
+
+  // Fetch other objects from the database.
   if ($queried_objects) {
     // The invoke order is:
     // - hook_field_attach_pre_load()
@@ -875,25 +984,88 @@ function field_attach_query_revisions($f
  *   The type of $object; e.g. 'node' or 'user'.
  * @param $object
  *   The object with fields to render.
- * @param $build_mode
- *   Build mode, e.g. 'full', 'teaser'...
+ * @param $teaser
+ *   Whether to display the teaser only, as on the main page.
  * @return
  *   A structured content array tree for drupal_render().
+ *   The 'view' operation constructs the $object in a way that you can use
+ *   drupal_render() to display the formatted output for an individual field.
+ *   i.e. print drupal_render($object->content['field_foo']);
+ *
+ *   The code supports both single value formatters, which theme an individual
+ *   item value, and multiple value formatters, which theme all values for the
+ *   field in a single theme. The multiple value formatters could be used, for
+ *   instance, to plot field values on a single map or display them in a graph.
+ *   Single value formatters are the default, multiple value formatters can be
+ *   designated as such in formatter_info().
+ *   The $object array will look like:
+ *     $object->content['field_foo']['wrapper'] = array(
+ *       '#theme' => 'field',
+ *       '#title' => label of field instance
+ *       '#field_name' => 'field_name',
+ *       '#object' => $object,
+ *       '#object_type' => $obj_type,
+ *       // Value of the $teaser param of hook_node('view').
+ *       '#teaser' => $teaser,
+ *       'items' =>
+ *         // One numbered sub-array for each field value.
+ *         // Only multiple form elements: one numbered sub-array
+ *         // for each field value.
+ *         0 => array(
+ *           '#item' => $items[0],
+ *           '#theme' => $theme,
+ *           '#field_name' => 'field_name',
+ *           '#bundle' => $bundle,
+ *           '#formatter' => $formatter_name,
+ *           '#settings' => $formatter_settings,
+ *           '#object' => $object,
+ *           '#object_type' => $obj_type,
+ *           '#delta' => 0,
+ *         ),
+ *         1 => array(
+ *           '#item' => $items[1],
+ *           '#theme' => $theme,
+ *           '#field_name' => 'field_name',
+ *           '#bundle' => $bundle_name,
+ *           '#formatter' => $formatter_name,
+ *           '#settings' => $formatter_settings,
+ *           '#object' => $object,
+ *           '#object_type' => $obj_type,
+ *           '#delta' => 1,
+ *         ),
+ *         '#theme' => $theme,
+ *         '#field_name' => 'field_name',
+ *         '#bundle' => $bundle_name,
+ *         '#formatter' => $formatter_name,
+ *         '#settings' => $formatter_settings,
+ *       ),
+ *     );
  */
-function field_attach_view($obj_type, $object, $build_mode = 'full') {
+function field_attach_view($obj_type, $object, $teaser = FALSE) {
   // Let field modules sanitize their data for output.
   _field_invoke('sanitize', $obj_type, $object);
 
-  $output = _field_invoke_default('view', $obj_type, $object, $build_mode);
+  $output = _field_invoke_default('view', $obj_type, $object, $teaser);
 
   // Let other modules make changes after rendering the view.
-  drupal_alter('field_attach_view', $output, $obj_type, $object, $build_mode);
+  drupal_alter('field_attach_view', $output, $obj_type, $object, $teaser);
 
   return $output;
 
 }
 
 /**
+ * To be called in entity preprocessor.
+ *
+ * - Adds $FIELD_NAME_rendered variables
+ *   containing the themed output for the whole field.
+ * - Adds the formatted values in the 'view' key of the items.
+ */
+function field_attach_preprocess($obj_type, $object) {
+  return _field_invoke_default('preprocess', $obj_type, $object);
+}
+
+/**
  * Implement hook_node_prepare_translation.
  *
  * TODO D7: We do not yet know if this really belongs in Field API.
Index: modules/field/field.default.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.default.inc,v
retrieving revision 1.10
diff -u -p -r1.10 field.default.inc
--- modules/field/field.default.inc	11 Jul 2009 00:56:45 -0000	1.10
+++ modules/field/field.default.inc	15 Jul 2009 11:17:20 -0000
@@ -50,61 +50,9 @@ function field_default_insert($obj_type,
     }
   }
 }
-
 /**
- * The 'view' operation constructs the $object in a way that you can use
- * drupal_render() to display the formatted output for an individual field.
- * i.e. print drupal_render($object->content['field_foo']);
- *
- * The code supports both single value formatters, which theme an individual
- * item value, and multiple value formatters, which theme all values for the
- * field in a single theme. The multiple value formatters could be used, for
- * instance, to plot field values on a single map or display them in a graph.
- * Single value formatters are the default, multiple value formatters can be
- * designated as such in formatter_info().
- *
- * The $object array will look like:
- *   $object->content['field_foo'] = array(
- *     '#theme' => 'field',
- *     '#title' => 'label'
- *     '#field_name' => 'field_name',
- *     '#object' => $object,
- *     '#object_type' => $obj_type,
- *     // Value of the $build_mode param of hook_node('view').
- *     '#build_mode' => $build_mode,
- *     'items' =>
- *       0 => array(
- *         '#item' => $items[0],
- *         // Only for 'single-value' formatters
- *         '#theme' => $theme,
- *         '#field_name' => 'field_name',
- *         '#bundle' => $bundle,
- *         '#formatter' => $formatter_name,
- *         '#settings' => $formatter_settings,
- *         '#object' => $object,
- *         '#object_type' => $obj_type,
- *         '#delta' => 0,
- *       ),
- *       1 => array(
- *         '#item' => $items[1],
- *         // Only for 'single-value' formatters
- *         '#theme' => $theme,
- *         '#field_name' => 'field_name',
- *         '#bundle' => $bundle_name,
- *         '#formatter' => $formatter_name,
- *         '#settings' => $formatter_settings,
- *         '#object' => $object,
- *         '#object_type' => $obj_type,
- *         '#delta' => 1,
- *       ),
- *       // Only for 'multiple-value' formatters
- *       '#theme' => $theme,
- *       '#field_name' => 'field_name',
- *       '#bundle' => $bundle_name,
- *       '#formatter' => $formatter_name,
- *       '#settings' => $formatter_settings,
- *     ),
- *   );
+ * Default field 'view' operation
+ * @see field_attach_view()
  */
 function field_default_view($obj_type, $object, $field, $instance, $items, $build_mode) {
   list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
