### Eclipse Workspace Patch 1.0
#P drupal_test_7
Index: modules/field/field.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.test,v
retrieving revision 1.34
diff -u -r1.34 field.test
--- modules/field/field.test	15 Jul 2009 17:55:18 -0000	1.34
+++ modules/field/field.test	18 Jul 2009 02:22:22 -0000
@@ -30,6 +30,7 @@
     $this->field_id = $this->field['id'];
     $this->instance = array(
       'field_name' => $this->field_name,
+      'object_type' => 'test_entity',
       'bundle' => 'test_bundle',
       'label' => $this->randomName() . '_label',
       'description' => $this->randomName() . '_description',
@@ -139,6 +140,7 @@
       foreach ($field_bundles_map[$i] as $bundle) {
         $instance = array(
           'field_name' => $field_names[$i],
+          'object_type' => 'test_entity',
           'bundle' => $bundles[$bundle],
           'settings' => array(
             // Configure the instance so that we test hook_field_load()
@@ -154,7 +156,7 @@
     foreach ($bundles as $index => $bundle) {
       $entities[$index] = field_test_create_stub_entity($index, $index, $bundle);
       $entity = clone($entities[$index]);
-      $instances = field_info_instances($bundle);
+      $instances = field_info_instances('test_entity', $bundle);
       foreach ($instances as $field_name => $instance) {
         $values[$index][$field_name] = mt_rand(1, 127);
         $entity->$field_name = array(array('value' => $values[$index][$field_name]));
@@ -165,7 +167,7 @@
     // Check that a single load correctly loads field values for both entities.
     field_attach_load($entity_type, $entities);
     foreach ($entities as $index => $entity) {
-      $instances = field_info_instances($bundles[$index]);
+      $instances = field_info_instances($entity_type, $bundles[$index]);
       foreach ($instances as $field_name => $instance) {
         // The field value loaded matches the one inserted.
         $this->assertEqual($entity->{$field_name}[0]['value'], $values[$index][$field_name], t('Entity %index: expected value was found.', array('%index' => $index)));
@@ -592,7 +594,7 @@
     $values = $this->_generateTestFieldValues($this->field['cardinality']);
     $entity->{$this->field_name} = $values;
     $entity_type = 'test_entity';
-    field_attach_insert($entity_type, $entity);
+    field_attach_insert('test_entity', $entity);
 
     // Verify the field data is present on load.
     $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
@@ -605,7 +607,7 @@
     field_test_rename_bundle($this->instance['bundle'], $new_bundle);
 
     // Check that the instance definition has been updated.
-    $this->instance = field_info_instance($this->field_name, $new_bundle);
+    $this->instance = field_info_instance($entity_type, $this->field_name, $new_bundle);
     $this->assertIdentical($this->instance['bundle'], $new_bundle, "Bundle name has been updated in the instance.");
 
     // Verify the field data is present on load.
@@ -630,6 +632,7 @@
     field_create_field($field);
     $instance = array(
       'field_name' => $field_name,
+      'object_type' => 'test_entity',
       'bundle' => $this->instance['bundle'],
       'label' => $this->randomName() . '_label',
       'description' => $this->randomName() . '_description',
@@ -646,12 +649,11 @@
     $values = $this->_generateTestFieldValues($this->field['cardinality']);
     $entity->{$this->field_name} = $values;
     $entity->{$field_name} = $this->_generateTestFieldValues(1);
-    $entity_type = 'test_entity';
-    field_attach_insert($entity_type, $entity);
+    field_attach_insert('test_entity', $entity);
 
     // Verify the fields are present on load
     $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
-    field_attach_load($entity_type, array(0 => $entity));
+    field_attach_load('test_entity', array(0 => $entity));
     $this->assertEqual(count($entity->{$this->field_name}), 4, "First field got loaded");
     $this->assertEqual(count($entity->{$field_name}), 1, "Second field got loaded");
 
@@ -661,13 +663,13 @@
 
     // Verify no data gets loaded
     $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
-    field_attach_load($entity_type, array(0 => $entity));
+    field_attach_load('test_entity', array(0 => $entity));
     $this->assertFalse(isset($entity->{$this->field_name}), "No data for first field");
     $this->assertFalse(isset($entity->{$field_name}), "No data for second field");
 
     // Verify that the instances are gone
-    $this->assertFalse(field_read_instance($this->field_name, $this->instance['bundle']), "First field is deleted");
-    $this->assertFalse(field_read_instance($field_name, $instance['bundle']), "Second field is deleted");
+    $this->assertFalse(field_read_instance('test_entity', $this->field_name, $this->instance['bundle']), "First field is deleted");
+    $this->assertFalse(field_read_instance('test_entity', $field_name, $instance['bundle']), "Second field is deleted");
   }
 
   /**
@@ -903,7 +905,7 @@
 
     // Verify that no unexpected instances exist.
     $core_fields = field_info_fields();
-    $instances = field_info_instances(FIELD_TEST_BUNDLE);
+    $instances = field_info_instances('test_entity', FIELD_TEST_BUNDLE);
     $this->assertTrue(empty($instances), t('With no instances, info bundles is empty.'));
 
     // Create a field, verify it shows up.
@@ -927,6 +929,7 @@
     // Create an instance, verify that it shows up
     $instance = array(
       'field_name' => $field['field_name'],
+      'object_type' => 'test_entity',
       'bundle' => FIELD_TEST_BUNDLE,
       'label' => $this->randomName(),
       'description' => $this->randomName(),
@@ -938,7 +941,7 @@
           'test_setting' => 999)));
     field_create_instance($instance);
 
-    $instances = field_info_instances($instance['bundle']);
+    $instances = field_info_instances('test_entity', $instance['bundle']);
     $this->assertEqual(count($instances), 1, t('One instance shows up in info when attached to a bundle.'));
     $this->assertTrue($instance < $instances[$instance['field_name']], t('Instance appears in info correctly'));
   }
@@ -983,6 +986,7 @@
     $this->field_unlimited = array('field_name' => drupal_strtolower($this->randomName()), 'type' => 'test_field', 'cardinality' => FIELD_CARDINALITY_UNLIMITED);
 
     $this->instance = array(
+      'object_type' => 'test_entity',
       'bundle' => 'test_bundle',
       'label' => $this->randomName() . '_label',
       'description' => $this->randomName() . '_description',
@@ -1432,6 +1436,7 @@
     // Create instances for each.
     $this->instance_definition = array(
       'field_name' => $this->field['field_name'],
+      'object_type' => 'test_entity',
       'bundle' => FIELD_TEST_BUNDLE,
       'widget' => array(
         'type' => 'test_field_widget',
@@ -1455,7 +1460,7 @@
 
     // Make sure that this field's instance is marked as deleted when it is
     // specifically loaded.
-    $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE));
+    $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE));
     $this->assertTrue(!empty($instance['deleted']), t('An instance for a deleted field is marked for deletion.'));
 
     // Try to load the field normally and make sure it does not show up.
@@ -1463,13 +1468,13 @@
     $this->assertTrue(empty($field), t('A deleted field is not loaded by default.'));
 
     // Try to load the instance normally and make sure it does not show up.
-    $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+    $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
     $this->assertTrue(empty($instance), t('An instance for a deleted field is not loaded by default.'));
 
     // Make sure the other field (and its field instance) are not deleted.
     $another_field = field_read_field($this->another_field['field_name']);
     $this->assertTrue(!empty($another_field) && empty($another_field['deleted']), t('A non-deleted field is not marked for deletion.'));
-    $another_instance = field_read_instance($this->another_instance_definition['field_name'], $this->another_instance_definition['bundle']);
+    $another_instance = field_read_instance('test_entity', $this->another_instance_definition['field_name'], $this->another_instance_definition['bundle']);
     $this->assertTrue(!empty($another_instance) && empty($another_instance['deleted']), t('An instance of a non-deleted field is not marked for deletion.'));
 
     // Try to create a new field the same name as a deleted field and
@@ -1478,7 +1483,7 @@
     field_create_instance($this->instance_definition);
     $field = field_read_field($this->field['field_name']);
     $this->assertTrue(!empty($field) && empty($field['deleted']), t('A new field with a previously used name is created.'));
-    $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+    $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
     $this->assertTrue(!empty($instance) && empty($instance['deleted']), t('A new instance for a previously used field name is created.'));
 
     // Save an object with data for the field
@@ -1486,7 +1491,7 @@
     $values[0]['value'] = mt_rand(1, 127);
     $entity->{$field['field_name']} = $values;
     $entity_type = 'test_entity';
-    field_attach_insert($entity_type, $entity);
+    field_attach_insert('test_entity', $entity);
 
     // Verify the field is present on load
     $entity = field_test_create_stub_entity(0, 0, $this->instance_definition['bundle']);
@@ -1518,6 +1523,7 @@
     field_create_field($this->field);
     $this->instance_definition = array(
       'field_name' => $this->field['field_name'],
+      'object_type' => 'test_entity',
       'bundle' => FIELD_TEST_BUNDLE,
     );
   }
@@ -1539,7 +1545,6 @@
     $record = $result->fetchAssoc();
     $record['data'] = unserialize($record['data']);
 
-    //$instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
     $field_type = field_info_field_types($this->field['type']);
     $widget_type = field_info_widget_types($field_type['default_widget']);
     $formatter_type = field_info_formatter_types($field_type['default_formatter']);
@@ -1619,7 +1624,7 @@
     $field_type = field_info_field_types($this->field['type']);
 
     // Check that basic changes are saved.
-    $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+    $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
     $instance['required'] = !$instance['required'];
     $instance['weight']++;
     $instance['label'] = $this->randomName();
@@ -1629,7 +1634,7 @@
     $instance['display']['full']['settings']['test_formatter_setting'] = $this->randomName();
     field_update_instance($instance);
 
-    $instance_new = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+    $instance_new = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
     $this->assertEqual($instance['required'], $instance_new['required'], t('"required" change is saved'));
     $this->assertEqual($instance['weight'], $instance_new['weight'], t('"weight" change is saved'));
     $this->assertEqual($instance['label'], $instance_new['label'], t('"label" change is saved'));
@@ -1638,12 +1643,12 @@
     $this->assertEqual($instance['display']['full']['settings']['test_formatter_setting'], $instance_new['display']['full']['settings']['test_formatter_setting'], t('Formatter setting change is saved'));
 
     // Check that changing widget and formatter types updates the default settings.
-    $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+    $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
     $instance['widget']['type'] = 'test_field_widget_multiple';
     $instance['display']['full']['type'] = 'field_test_multiple';
     field_update_instance($instance);
 
-    $instance_new = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+    $instance_new = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
     $this->assertEqual($instance['widget']['type'], $instance_new['widget']['type'] , t('Widget type change is saved.'));
     $settings = field_info_widget_settings($instance_new['widget']['type']);
     $this->assertIdentical($settings, array_intersect_key($instance_new['widget']['settings'], $settings) , t('Widget type change updates default settings.'));
@@ -1653,11 +1658,11 @@
     $this->assertIdentical($settings, array_intersect_key($instance_new['display']['full']['settings'], $settings) , t('Changing formatter type updates default settings.'));
 
     // Check that adding a new build mode is saved and gets default settings.
-    $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+    $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
     $instance['display']['teaser'] = array();
     field_update_instance($instance);
 
-    $instance_new = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+    $instance_new = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
     $this->assertTrue(isset($instance_new['display']['teaser']), t('Display for the new build_mode has been written.'));
     $this->assertIdentical($instance_new['display']['teaser']['type'], $field_type['default_formatter'], t('Default formatter for the new build_mode has been written.'));
     $info = field_info_formatter_types($instance_new['display']['teaser']['type']);
@@ -1683,21 +1688,21 @@
     field_create_instance($this->another_instance_definition);
 
     // Test that the first instance is not deleted, and then delete it.
-    $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE));
+    $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE));
     $this->assertTrue(!empty($instance) && empty($instance['deleted']), t('A new field instance is not marked for deletion.'));
-    field_delete_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+    field_delete_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
 
     // Make sure the instance is marked as deleted when the instance is
     // specifically loaded.
-    $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE));
+    $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE));
     $this->assertTrue(!empty($instance['deleted']), t('A deleted field instance is marked for deletion.'));
 
     // Try to load the instance normally and make sure it does not show up.
-    $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+    $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
     $this->assertTrue(empty($instance), t('A deleted field instance is not loaded by default.'));
 
     // Make sure the other field instance is not deleted.
-    $another_instance = field_read_instance($this->another_instance_definition['field_name'], $this->another_instance_definition['bundle']);
+    $another_instance = field_read_instance('test_entity', $this->another_instance_definition['field_name'], $this->another_instance_definition['bundle']);
     $this->assertTrue(!empty($another_instance) && empty($another_instance['deleted']), t('A non-deleted field instance is not marked for deletion.'));
   }
 }
Index: modules/field/field.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.install,v
retrieving revision 1.9
diff -u -r1.9 field.install
--- modules/field/field.install	28 May 2009 10:05:32 -0000	1.9
+++ modules/field/field.install	18 Jul 2009 02:22:20 -0000
@@ -101,6 +101,7 @@
         'description' => 'The identifier of the field attached by this instance',
       ),
       'field_name'        => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
+      'object_type'       => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
       'bundle'            => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
       'widget_type'       => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
       'widget_module'     => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
@@ -130,7 +131,7 @@
     ),
     'primary key' => array('id'),
     'unique keys' => array(
-      'field_id_bundle' => array('field_id', 'bundle'),
+      'field_id_bundle' => array('field_id', 'object_type', 'bundle'),
     ),
     'indexes' => array(
       // used by field_read_instances()
Index: modules/field/field.crud.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.crud.inc,v
retrieving revision 1.21
diff -u -r1.21 field.crud.inc
--- modules/field/field.crud.inc	14 Jul 2009 10:27:29 -0000	1.21
+++ modules/field/field.crud.inc	18 Jul 2009 02:22:20 -0000
@@ -16,6 +16,7 @@
  * particular type of data that can be attached to objects. A Field
  * Instance is a Field attached to a single Bundle. A Bundle is a set
  * of fields that are treated as a group by the Field Attach API.
+ * TODO...
  *
  * For example, suppose a site administrator wants Article nodes to
  * have a subtitle and photo. Using the Field API or some UI module,
@@ -87,6 +88,8 @@
  *     It is populated automatically by field_create_instance().
  * - field_name (string)
  *     The name of the field attached to the bundle by this instance.
+ * - object_type (string)
+ *     The name of the object type the instance is attached to.
  * - bundle (string)
  *     The name of the bundle that the field is attached to.
  * - label (string)
@@ -438,7 +441,7 @@
 
   // Ensure the field instance is unique.
   // TODO : do we want specific messages when clashing with a disabled or inactive instance ?
-  $prior_instance = field_read_instance($instance['field_name'], $instance['bundle'], array('include_inactive' => TRUE));
+  $prior_instance = field_read_instance($instance['object_type'], $instance['field_name'], $instance['bundle'], array('include_inactive' => TRUE));
   if (!empty($prior_instance)) {
     throw new FieldException('Attempt to create a field instance which already exists.');
   }
@@ -478,7 +481,7 @@
 
   // Check that the field instance exists (even if it is inactive, since we
   // want to be able to replace inactive widgets with new ones).
-  $prior_instance = field_read_instance($instance['field_name'], $instance['bundle'], array('include_inactive' => TRUE));
+  $prior_instance = field_read_instance($instance['object_type'], $instance['field_name'], $instance['bundle'], array('include_inactive' => TRUE));
   if (empty($prior_instance)) {
     throw new FieldException("Attempt to update a field instance that doesn't exist.");
   }
@@ -557,6 +560,7 @@
   $data = $instance;
   unset($data['id'], $data['field_id'], $data['field_name'], $data['bundle'], $data['widget']['type'], $data['weight'], $data['deleted']);
 
+  // TODO : obj_type
   $record = array(
     'field_id' => $instance['field_id'],
     'field_name' => $instance['field_name'],
@@ -586,7 +590,7 @@
  *
  * This function will not return deleted instances. Use
  * field_read_instances() instead for this purpose.
- *
+ * TODO
  * @param $field_name
  *   The field name to read.
  * @param $bundle
@@ -599,8 +603,8 @@
  * @return
  *   An instance structure, or FALSE.
  */
-function field_read_instance($field_name, $bundle, $include_additional = array()) {
-  $instances = field_read_instances(array('field_name' => $field_name, 'bundle' => $bundle), $include_additional);
+function field_read_instance($obj_type, $field_name, $bundle, $include_additional = array()) {
+  $instances = field_read_instances(array('object_type' => $obj_type, 'field_name' => $field_name, 'bundle' => $bundle), $include_additional);
   return $instances ? current($instances) : FALSE;
 }
 
@@ -647,6 +651,7 @@
     $instance['id'] = $record['id'];
     $instance['field_id'] = $record['field_id'];
     $instance['field_name'] = $record['field_name'];
+    $instance['object_type'] = $record['object_type'];
     $instance['bundle'] = $record['bundle'];
     $instance['weight'] = $record['weight'];
     $instance['deleted'] = $record['deleted'];
@@ -677,16 +682,17 @@
  * @param $bundle
  *   The bundle for the instance which will be deleted.
  */
-function field_delete_instance($field_name, $bundle) {
+function field_delete_instance($obj_type, $field_name, $bundle) {
   // Mark the field instance for deletion.
   db_update('field_config_instance')
     ->fields(array('deleted' => 1))
     ->condition('field_name', $field_name)
+    // TODO condition on obj_type
     ->condition('bundle', $bundle)
     ->execute();
 
   // Mark all data associated with the field for deletion.
-  module_invoke(variable_get('field_storage_module', 'field_sql_storage'), 'field_storage_delete_instance', $field_name, $bundle);
+  module_invoke(variable_get('field_storage_module', 'field_sql_storage'), 'field_storage_delete_instance', $obj_type, $field_name, $bundle);
   // Clear the cache.
   field_cache_clear();
 }
Index: modules/field/field.info.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.info.inc,v
retrieving revision 1.8
diff -u -r1.8 field.info.inc
--- modules/field/field.info.inc	10 Jul 2009 05:58:13 -0000	1.8
+++ modules/field/field.info.inc	18 Jul 2009 02:22:20 -0000
@@ -162,12 +162,12 @@
  *   If $reset is TRUE, nothing.
  *   If $reset is FALSE, an array containing the following elements:
  *
- *   - fields: array of all defined Field objects, keyed by field
- *     name. Each field has an additional element, bundles, which is
- *     an array of all bundles to which the field is assigned.
- *   - instances: array whose keys are bundle names and whose values
- *     are an array, keyed by field name, of all Instance objects in
- *     that bundle.
+ *   - fields: array of all defined Field objects, keyed by field name. Each
+ *     field has an additional element, bundles, which is an array, keyed by
+ *     object type, of all bundles to which the field is assigned.
+ *   - instances: array keyed by object type then by bundle name, whose values
+ *     are an array, keyed by field name, of all instances objects in that
+ *     bundle.
  */
 function _field_info_collate_fields($reset = FALSE) {
   static $info;
@@ -185,14 +185,19 @@
     else {
       $info = array(
         'fields' => field_read_fields(),
-        'instances' => array_fill_keys(array_keys(field_info_bundles()), array()),
       );
+      // Initialize the array of instances.
+      foreach (field_info_bundles() as $obj_type => $bundles) {
+        foreach ($bundles as $bundle => $bundle_info) {
+          $info['instances'][$obj_type][$bundle] = array();
+        }
+      }
 
       // Populate instances.
       $instances = field_read_instances();
       foreach ($instances as $instance) {
-        $info['instances'][$instance['bundle']][$instance['field_name']] = $instance;
-        $info['fields'][$instance['field_name']]['bundles'][] = $instance['bundle'];
+        $info['instances'][$instance['object_type']][$instance['bundle']][$instance['field_name']] = $instance;
+        $info['fields'][$instance['field_name']]['bundles'][$instance['object_type']][] = $instance['bundle'];
       }
 
       cache_set('field_info_fields', $info, 'cache_field');
@@ -354,16 +359,26 @@
 }
 
 /**
- * Return an array of fieldable bundle names and labels, for an individual
- * object type or for all object types.
+ * Return information about existing bundles.
+ *
+ * @param $obj_type
+ *   The type of object; e.g. 'node' or 'user'.
+ *
+ * @return
+ *   An array of bundles for the $obj_type keyed by bundle name,
+ *   or, if no $obj_type was provided, the array of all existing bundles,
+ *   keyed by object type.
  */
 function field_info_bundles($obj_type = NULL) {
   $info = _field_info_collate_types();
+
+  if ($obj_type) {
+    return isset($info['fieldable types'][$obj_type]['bundles']) ? $info['fieldable types'][$obj_type]['bundles'] : array();
+  }
+
   $bundles = array();
   foreach ($info['fieldable types'] as $type => $fieldable_info) {
-    if (empty($obj_type) || $obj_type == $type) {
-      $bundles += $fieldable_info['bundles'];
-    }
+    $bundles[$type] = $fieldable_info['bundles'];
   }
   return $bundles;
 }
@@ -416,28 +431,29 @@
 /**
  * Return an array of instance data for a given bundle,
  * or for all known bundles, keyed by bundle name and field name.
- *
+ * TODO
  * @param $bundle_name
  *   If set, return information on just this bundle.
  */
-function field_info_instances($bundle_name = NULL) {
+function field_info_instances($obj_type, $bundle_name = NULL) {
   $info = _field_info_collate_fields();
   if (!isset($bundle_name)) {
-    return $info['instances'];
+    return $info['instances'][$obj_type];
   }
-  if (isset($info['instances'][$bundle_name])) {
-    return $info['instances'][$bundle_name];
+  if (isset($info['instances'][$obj_type][$bundle_name])) {
+    return $info['instances'][$obj_type][$bundle_name];
   }
   return array();
 }
 
 /**
  * Return an array of instance data for a specific field and bundle.
+ * TODO
  */
-function field_info_instance($field_name, $bundle_name) {
+function field_info_instance($obj_type, $field_name, $bundle_name) {
   $info = _field_info_collate_fields();
-  if (isset($info['instances'][$bundle_name][$field_name])) {
-    return $info['instances'][$bundle_name][$field_name];
+  if (isset($info['instances'][$obj_type][$bundle_name][$field_name])) {
+    return $info['instances'][$obj_type][$bundle_name][$field_name];
   }
 }
 
Index: modules/field/field.attach.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.attach.inc,v
retrieving revision 1.33
diff -u -r1.33 field.attach.inc
--- modules/field/field.attach.inc	16 Jul 2009 10:30:12 -0000	1.33
+++ modules/field/field.attach.inc	18 Jul 2009 02:22:19 -0000
@@ -172,7 +172,7 @@
   // Iterate through the object's field instances.
   $return = array();
   list(, , $bundle) = field_attach_extract_ids($obj_type, $object);
-  foreach (field_info_instances($bundle) as $instance) {
+  foreach (field_info_instances($obj_type, $bundle) as $instance) {
     $field_name = $instance['field_name'];
 
     // When in 'single field' mode, only act on the specified field.
@@ -261,7 +261,7 @@
   // invoked.
   foreach ($objects as $object) {
     list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
-    foreach (field_info_instances($bundle) as $instance) {
+    foreach (field_info_instances($obj_type, $bundle) as $instance) {
       $field_name = $instance['field_name'];
       // When in 'single field' mode, only act on the specified field.
       if (empty($options['field_name']) || $options['field_name'] == $field_name) {
@@ -465,7 +465,7 @@
       foreach ($queried_objects as $id => $object) {
         $data = array();
         list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
-        $instances = field_info_instances($bundle);
+        $instances = field_info_instances($obj_type, $bundle);
         foreach ($instances as $instance) {
           $data[$instance['field_name']] = $queried_objects[$id]->{$instance['field_name']};
         }
@@ -918,34 +918,35 @@
  *
  * The default SQL-based storage doesn't need to do anytrhing about it, but
  * others might.
- *
+ *  TODO
  * @param $bundle
  *   The name of the newly created bundle.
  */
-function field_attach_create_bundle($bundle) {
-  module_invoke(variable_get('field_storage_module', 'field_sql_storage'), 'field_storage_create_bundle', $bundle);
+function field_attach_create_bundle($obj_type, $bundle) {
+  module_invoke(variable_get('field_storage_module', 'field_sql_storage'), 'field_storage_create_bundle', $obj_type, $bundle);
 
   // Clear the cache.
   field_cache_clear();
 
   foreach (module_implements('field_attach_create_bundle') as $module) {
     $function = $module . '_field_attach_create_bundle';
-    $function($bundle);
+    $function($obj_type, $bundle);
   }
 }
 
 /**
  * Notify field.module that a bundle was renamed.
- *
+ * TODO
  * @param $bundle_old
  *   The previous name of the bundle.
  * @param $bundle_new
  *   The new name of the bundle.
  */
-function field_attach_rename_bundle($bundle_old, $bundle_new) {
-  module_invoke(variable_get('field_storage_module', 'field_sql_storage'), 'field_storage_rename_bundle', $bundle_old, $bundle_new);
+function field_attach_rename_bundle($obj_type, $bundle_old, $bundle_new) {
+  module_invoke(variable_get('field_storage_module', 'field_sql_storage'), 'field_storage_rename_bundle', $obj_type, $bundle_old, $bundle_new);
   db_update('field_config_instance')
     ->fields(array('bundle' => $bundle_new))
+    // TODO condition on $obj_type
     ->condition('bundle', $bundle_old)
     ->execute();
 
@@ -954,7 +955,7 @@
 
   foreach (module_implements('field_attach_rename_bundle') as $module) {
     $function = $module . '_field_attach_rename_bundle';
-    $function($bundle_old, $bundle_new);
+    $function($obj_type, $bundle_old, $bundle_new);
   }
 }
 
@@ -967,21 +968,23 @@
  * it is not always possible to delete this much data in a single page request
  * (particularly since for some field types, the deletion is more than just a
  * simple DELETE query).
- *
+ * TODO
  * @param $bundle
  *   The bundle to delete.
  */
-function field_attach_delete_bundle($bundle) {
+function field_attach_delete_bundle($obj_type, $bundle) {
   // Delete the instances themseves
-  $instances = field_info_instances($bundle);
+  $instances = field_info_instances($obj_type, $bundle);
   foreach ($instances as $instance) {
-    field_delete_instance($instance['field_name'], $bundle);
+    field_delete_instance($obj_type, $instance['field_name'], $bundle);
   }
 
+  module_invoke(variable_get('field_storage_module', 'field_sql_storage'), 'field_storage_delete_bundle', $obj_type, $bundle, $instances);
+
   // Let other modules act on deleting the bundle.
   foreach (module_implements('field_attach_delete_bundle') as $module) {
     $function = $module . '_field_attach_delete_bundle';
-    $function($bundle, $instances);
+    $function($obj_type, $bundle, $instances);
   }
 }
 
Index: modules/field/field.default.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.default.inc,v
retrieving revision 1.10
diff -u -r1.10 field.default.inc
--- modules/field/field.default.inc	11 Jul 2009 00:56:45 -0000	1.10
+++ modules/field/field.default.inc	18 Jul 2009 02:22:20 -0000
@@ -128,9 +128,9 @@
 
     $info = array(
       '#field_name' => $field['field_name'],
+      '#object_type' => $obj_type,
       '#bundle' => $bundle,
       '#object' => $object,
-      '#object_type' => $obj_type,
     );
 
     $element = $info + array(
Index: modules/field/field.api.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.api.php,v
retrieving revision 1.21
diff -u -r1.21 field.api.php
--- modules/field/field.api.php	15 Jul 2009 17:55:18 -0000	1.21
+++ modules/field/field.api.php	18 Jul 2009 02:22:19 -0000
@@ -764,7 +764,7 @@
  *
  * See field_attach_create_bundle() for details and arguments.
  */
-function hook_field_attach_create_bundle($bundle) {
+function hook_field_attach_create_bundle($obj_type, $bundle) {
 }
 
 /**
@@ -774,7 +774,7 @@
  *
  * See field_attach_rename_bundle() for details and arguments.
  */
-function hook_field_attach_rename_bundle($bundle_old, $bundle_new) {
+function hook_field_attach_rename_bundle($obj_type, $bundle_old, $bundle_new) {
 }
 
 /**
@@ -782,13 +782,15 @@
  *
  * This hook is invoked after the field module has performed the operation.
  *
+ * @param $obj_type
+ *   The type of object; e.g. 'node' or 'user'.
  * @param $bundle
  *   The bundle that was just deleted.
  * @param $instances
- *   An array of all instances that existed for $bundle before it was
+ *   An array of all instances that existed for the bundle before it was
  *   deleted.
  */
-function hook_field_attach_delete_bundle($bundle, $instances) {
+function hook_field_attach_delete_bundle($obj_type, $bundle, $instances) {
 }
 
 /**
@@ -895,22 +897,40 @@
 
 /**
  * Act on creation of a new bundle.
- *
+ * @param $obj_type
+ *   The type of object; e.g. 'node' or 'user'.
+
  * @param $bundle
  *   The name of the bundle being created.
  */
-function hook_field_storage_create_bundle($bundle) {
+function hook_field_storage_create_bundle($obj_type, $bundle) {
 }
 
 /**
  * Act on a bundle being renamed.
  *
+ * @param $obj_type
+ *   The type of object; e.g. 'node' or 'user'.
  * @param $bundle_old
  *   The old name of the bundle.
  * @param $bundle_new
  *   The new name of the bundle.
  */
-function hook_field_storage_rename_bundle($bundle_old, $bundle_new) {
+function hook_field_storage_rename_bundle($obj_type, $bundle_old, $bundle_new) {
+}
+
+/**
+ * Act on deletion of a bundle.
+ *
+ * @param $obj_type
+ *   The type of object; e.g. 'node' or 'user'.
+ * @param $bundle
+ *   The name of the bundle being deleted.
+ * @param $instances
+ *   An array of all instances that existed for $bundle before it was
+ *   deleted.
+ */
+function hook_field_storage_delete_bundle($obj_type, $bundle, $instances) {
 }
 
 /**
@@ -934,12 +954,14 @@
 /**
  * Act on deletion of a field instance.
  *
+ * @param $obj_type
+ *   The type of object; e.g. 'node' or 'user'.
  * @param $field_name
  *   The name of the field in the new instance.
  * @param $bundle
  *   The name of the bundle in the new instance.
  */
-function hook_field_storage_delete_instance($field_name, $bundle) {
+function hook_field_storage_delete_instance($obj_type, $field_name, $bundle) {
 }
 
 /**
Index: modules/field/field.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.module,v
retrieving revision 1.20
diff -u -r1.20 field.module
--- modules/field/field.module	15 Jul 2009 17:55:18 -0000	1.20
+++ modules/field/field.module	18 Jul 2009 02:22:20 -0000
@@ -410,7 +410,7 @@
   if (field_access('view', $field)) {
     // Basically, we need $field, $instance, $obj_type, $object to be able to display a value...
     list(, , $bundle) = field_attach_extract_ids($obj_type, $object);
-    $instance = field_info_instance($field['field_name'], $bundle);
+    $instance = field_info_instance($obj_type, $field['field_name'], $bundle);
 
     $display = array(
       'type' => $formatter_name,
@@ -423,6 +423,7 @@
       $element = array(
         '#theme' => $theme,
         '#field_name' => $field['field_name'],
+        '#object_type' => $obj_type,
         '#bundle' => $bundle,
         '#formatter' => $display['type'],
         '#settings' => $display['settings'],
@@ -552,7 +553,7 @@
 function template_preprocess_field(&$variables) {
   $element = $variables['element'];
   list(, , $bundle) = field_attach_extract_ids($element['#object_type'], $element['#object']);
-  $instance = field_info_instance($element['#field_name'], $bundle);
+  $instance = field_info_instance($element['#object_type'], $element['#field_name'], $bundle);
   $field = field_info_field($element['#field_name']);
 
   $variables['object'] = $element['#object'];
Index: modules/field/field.form.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.form.inc,v
retrieving revision 1.11
diff -u -r1.11 field.form.inc
--- modules/field/field.form.inc	11 Jul 2009 00:56:45 -0000	1.11
+++ modules/field/field.form.inc	18 Jul 2009 02:22:20 -0000
@@ -72,6 +72,7 @@
           '#delta' => $delta,
           '#field_name' => $field['field_name'],
           '#bundle' => $instance['bundle'],
+          '#object_type' => $instance['object_type'],
         );
         $element = array_merge($element, $defaults);
         // If we're processing a specific delta value for a field where the
@@ -161,6 +162,7 @@
           '#delta' => $delta,
           '#columns' => array_keys($field['columns']),
           '#field_name' => $field_name,
+          '#object_type' => $instance['object_type'],
           '#bundle' => $instance['bundle'],
         );
 
@@ -201,11 +203,10 @@
           'method' => 'replace',
           'effect' => 'fade',
         ),
+        '#attributes' => array('class' => 'field-add-more-submit'),
         // When JS is disabled, the field_add_more_submit handler will find
-        // the relevant field using these entries.
+        // the relevant field using this entry.
         '#field_name' => $field_name,
-        '#bundle' => $instance['bundle'],
-        '#attributes' => array('class' => 'field-add-more-submit'),
       );
     }
   }
Index: modules/field/modules/options/options.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/options/options.module,v
retrieving revision 1.7
diff -u -r1.7 options.module
--- modules/field/modules/options/options.module	28 May 2009 16:44:06 -0000	1.7
+++ modules/field/modules/options/options.module	18 Jul 2009 02:22:23 -0000
@@ -291,8 +291,8 @@
 function options_data2form($element, $items, $field) {
   $field_key  = $element['#columns'][0];
   $field = field_info_field($element['#field_name']);
-  $instance = field_info_instance($element['#field_name'], $element['#bundle']);
-  $options    = options_options($field, $instance);
+  $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
+  $options = options_options($field, $instance);
 
   $items_transposed = options_transpose_array_rows_cols($items);
   $values = (isset($items_transposed[$field_key]) && is_array($items_transposed[$field_key])) ? $items_transposed[$field_key] : array();
@@ -319,7 +319,7 @@
 function options_form2data($element, $field) {
   $field_key = $element['#columns'][0];
   $field = field_info_field($element['#field_name']);
-  $instance = field_info_instance($element['#field_name'], $element['#bundle']);
+  $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
   $items = (array) $element[$field_key]['#value'];
   $options = options_options($field, $instance);
 
Index: modules/node/node.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.install,v
retrieving revision 1.24
diff -u -r1.24 node.install
--- modules/node/node.install	18 Jun 2009 15:46:30 -0000	1.24
+++ modules/node/node.install	18 Jul 2009 02:22:24 -0000
@@ -423,6 +423,7 @@
   $node_types = node_type_get_types();
   $body_types = array();
   foreach ($node_types as $type => $info) {
+    field_attach_create_bundle('node', $type);
     if ($info->has_body) {
       $body_types[] = $type;
     }
Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.1082
diff -u -r1.1082 node.module
--- modules/node/node.module	10 Jul 2009 05:58:13 -0000	1.1082
+++ modules/node/node.module	18 Jul 2009 02:22:26 -0000
@@ -429,7 +429,7 @@
       ->execute();
 
     if (!empty($type->old_type) && $type->old_type != $type->type) {
-      field_attach_rename_bundle($type->old_type, $type->type);
+      field_attach_rename_bundle('node', $type->old_type, $type->type);
     }
     node_configure_fields($type);
     module_invoke_all('node_type', 'update', $type);
@@ -441,7 +441,7 @@
       ->fields($fields)
       ->execute();
 
-    field_attach_create_bundle($type->type);
+    field_attach_create_bundle('node', $type->type);
     node_configure_fields($type);
     module_invoke_all('node_type', 'insert', $type);
     return SAVED_NEW;
@@ -461,7 +461,7 @@
 function node_configure_fields($type) {
    // Add or remove the body field, as needed.
   $field = field_info_field('body');
-  $instance = field_info_instance('body', $type->type);
+  $instance = field_info_instance('node', 'body', $type->type);
   if ($type->has_body) {
     if (empty($field)) {
       $field = array(
@@ -473,6 +473,7 @@
     if (empty($instance)) {
       $instance = array(
         'field_name' => 'body',
+        'object_type' => 'node',
         'bundle' => $type->type,
         'label' => $type->body_label,
         'widget_type' => 'text_textarea_with_summary',
@@ -502,9 +503,8 @@
     }
   }
   elseif (!empty($instance)) {
-    field_delete_instance($instance);
+    field_delete_instance('node', $instance['field_name'], $instance['bundle']);
   }
-
 }
 
 /**
@@ -518,6 +518,8 @@
   db_delete('node_type')
     ->condition('type', $type)
     ->execute();
+
+  field_attach_delete_bundle('node', $type);
   module_invoke_all('node_type', 'delete', $info);
 }
 
Index: modules/field/modules/text/text.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/text/text.test,v
retrieving revision 1.8
diff -u -r1.8 text.test
--- modules/field/modules/text/text.test	13 Jul 2009 21:51:09 -0000	1.8
+++ modules/field/modules/text/text.test	18 Jul 2009 02:22:24 -0000
@@ -37,6 +37,7 @@
     field_create_field($this->field);
     $this->instance = array(
       'field_name' => $this->field['field_name'],
+      'object_type' => 'test_entity',
       'bundle' => FIELD_TEST_BUNDLE,
       'widget' => array(
         'type' => 'text_textfield',
@@ -81,6 +82,7 @@
     field_create_field($this->field);
     $this->instance = array(
       'field_name' => $this->field_name,
+      'object_type' => 'test_entity',
       'bundle' => FIELD_TEST_BUNDLE,
       'label' => $this->randomName() . '_label',
       'settings' => array(
@@ -133,6 +135,7 @@
     field_create_field($this->field);
     $this->instance = array(
       'field_name' => $this->field_name,
+      'object_type' => 'test_entity',
       'bundle' => FIELD_TEST_BUNDLE,
       'label' => $this->randomName() . '_label',
       'settings' => array(
Index: modules/field/modules/text/text.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/text/text.module,v
retrieving revision 1.15
diff -u -r1.15 text.module
--- modules/field/modules/text/text.module	3 Jul 2009 18:19:29 -0000	1.15
+++ modules/field/modules/text/text.module	18 Jul 2009 02:22:24 -0000
@@ -299,7 +299,7 @@
  */
 function theme_field_formatter_text_trimmed($element) {
   $field = field_info_field($element['#field_name']);
-  $instance = field_info_instance($element['#field_name'], $element['#bundle']);
+  $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
   return text_summary($element['#item']['safe'], $instance['settings']['text_processing'] ? $element['#item']['format'] : NULL);
 }
 
@@ -311,7 +311,7 @@
  */
 function theme_field_formatter_text_summary_or_trimmed($element) {
   $field = field_info_field($element['#field_name']);
-  $instance = field_info_instance($element['#field_name'], $element['#bundle']);
+  $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
 
   if (!empty($element['#item']['safe_summary'])) {
     return $element['#item']['safe_summary'];
Index: modules/field/modules/number/number.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/number/number.module,v
retrieving revision 1.10
diff -u -r1.10 number.module
--- modules/field/modules/number/number.module	28 May 2009 16:44:06 -0000	1.10
+++ modules/field/modules/number/number.module	18 Jul 2009 02:22:23 -0000
@@ -176,7 +176,7 @@
  */
 function theme_field_formatter_number($element) {
   $field = field_info_field($element['#field_name']);
-  $instance = field_info_instance($element['#field_name'], $element['#bundle']);
+  $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
   $value = $element['#item']['value'];
   $settings = $element['#settings'];
   $formatter_type = $element['#formatter'];
@@ -299,7 +299,7 @@
 function number_elements_process($element, $form_state, $form) {
   $field_name = $element['#field_name'];
   $field = field_info_field($element['#field_name']);
-  $instance = field_info_instance($element['#field_name'], $element['#bundle']);
+  $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
   $field_key  = $element['#columns'][0];
 
   $value = isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : '';
@@ -321,6 +321,7 @@
     '#description' => $element['#description'],
     '#required' => $element['#required'],
     '#field_name' => $element['#field_name'],
+    '#object_type' => $element['#object_type'],
     '#bundle' => $element['#bundle'],
     '#delta' => $element['#delta'],
     '#columns' => $element['#columns'],
@@ -359,7 +360,7 @@
  */
 function number_float_validate($element, &$form_state) {
   $field = field_info_field($element['#field_name']);
-  $instance = field_info_instance($element['#field_name'], $element['#bundle']);
+  $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
   $field_key = $element['#columns'][0];
   $value = $element['#value'][$field_key];
 
@@ -381,7 +382,7 @@
  */
 function number_integer_validate($element, &$form_state) {
   $field = field_info_field($element['#field_name']);
-  $instance = field_info_instance($element['#field_name'], $element['#bundle']);
+  $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
   $field_key = $element['#columns'][0];
   $value = $element['#value'][$field_key];
 
@@ -403,7 +404,7 @@
  */
 function number_decimal_validate($element, &$form_state) {
   $field = field_info_field($element['#field_name']);
-  $instance = field_info_instance($element['#field_name'], $element['#bundle']);
+  $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
   $field_key = $element['#columns'][0];
   $value = $element['#value'][$field_key];
 
Index: modules/field/modules/field_sql_storage/field_sql_storage.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/field_sql_storage/field_sql_storage.module,v
retrieving revision 1.17
diff -u -r1.17 field_sql_storage.module
--- modules/field/modules/field_sql_storage/field_sql_storage.module	15 Jul 2009 17:55:18 -0000	1.17
+++ modules/field/modules/field_sql_storage/field_sql_storage.module	18 Jul 2009 02:22:22 -0000
@@ -211,7 +211,7 @@
   $delta_count = array();
   foreach ($objects as $obj) {
     list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $obj);
-    foreach (field_info_instances($bundle) as $field_name => $instance) {
+    foreach (field_info_instances($obj_type, $bundle) as $field_name => $instance) {
       if (!isset($skip_fields[$field_name]) && (!isset($options['field_name']) || $options['field_name'] == $instance['field_name'])) {
         $objects[$id]->{$field_name} = array();
         $field_ids[$field_name][] = $load_current ? $id : $vid;
@@ -258,7 +258,7 @@
   list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
   $etid = _field_sql_storage_etid($obj_type);
 
-  $instances = field_info_instances($bundle);
+  $instances = field_info_instances($obj_type, $bundle);
   foreach ($instances as $instance) {
     $field_name = $instance['field_name'];
     if (isset($skip_fields[$field_name])) {
@@ -335,7 +335,7 @@
   list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
   $etid = _field_sql_storage_etid($obj_type);
 
-  $instances = field_info_instances($bundle);
+  $instances = field_info_instances($obj_type, $bundle);
   foreach ($instances as $instance) {
     $field_name = $instance['field_name'];
     $field = field_read_field($field_name);
@@ -452,7 +452,7 @@
   $etid = _field_sql_storage_etid($obj_type);
 
   if (isset($vid)) {
-    $instances = field_info_instances($bundle);
+    $instances = field_info_instances($obj_type, $bundle);
     foreach ($instances as $instance) {
       $field_name = $instance['field_name'];
       $field = field_read_field($field_name);
@@ -471,15 +471,17 @@
  *
  * This function simply marks for deletion all data associated with the field.
  */
-function field_sql_storage_field_storage_delete_instance($field_name, $bundle) {
+function field_sql_storage_field_storage_delete_instance($obj_type, $field_name, $bundle) {
   $field = field_read_field($field_name);
   $table_name = _field_sql_storage_tablename($field);
   $revision_name = _field_sql_storage_revision_tablename($field);
   db_update($table_name)
+    // TODO condition on obj-type
     ->fields(array('deleted' => 1))
     ->condition('bundle', $bundle)
     ->execute();
   db_update($revision_name)
+    // TODO condition on obj-type
     ->fields(array('deleted' => 1))
     ->condition('bundle', $bundle)
     ->execute();
@@ -488,18 +490,20 @@
 /**
  * Implement hook_field_storage_rename_bundle().
  */
-function field_sql_storage_field_storage_rename_bundle($bundle_old, $bundle_new) {
-  $instances = field_info_instances($bundle_old);
+function field_sql_storage_field_storage_rename_bundle($obj_type, $bundle_old, $bundle_new) {
+  $instances = field_info_instances($obj_type, $bundle_old);
   foreach ($instances as $instance) {
     $field = field_read_field($instance['field_name']);
     $table_name = _field_sql_storage_tablename($field);
     $revision_name = _field_sql_storage_revision_tablename($field);
     db_update($table_name)
       ->fields(array('bundle' => $bundle_new))
+      // TODO : condition on obj_type
       ->condition('bundle', $bundle_old)
       ->execute();
     db_update($revision_name)
       ->fields(array('bundle' => $bundle_new))
+      // TODO : condition on obj_type
       ->condition('bundle', $bundle_old)
       ->execute();
   }
Index: modules/field/modules/field_sql_storage/field_sql_storage.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/field_sql_storage/field_sql_storage.test,v
retrieving revision 1.5
diff -u -r1.5 field_sql_storage.test
--- modules/field/modules/field_sql_storage/field_sql_storage.test	13 Jul 2009 21:51:09 -0000	1.5
+++ modules/field/modules/field_sql_storage/field_sql_storage.test	18 Jul 2009 02:22:23 -0000
@@ -28,6 +28,7 @@
     $this->field = field_create_field($this->field);
     $this->instance = array(
       'field_name' => $this->field_name,
+      'object_type' => 'test_entity',
       'bundle' => 'test_bundle'
     );
     $this->instance = field_create_instance($this->instance);
Index: modules/taxonomy/taxonomy.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.install,v
retrieving revision 1.20
diff -u -r1.20 taxonomy.install
--- modules/taxonomy/taxonomy.install	18 Jun 2009 15:46:30 -0000	1.20
+++ modules/taxonomy/taxonomy.install	18 Jul 2009 02:22:28 -0000
@@ -358,7 +358,7 @@
       ->fields(array('machine_name' => 'vocabulary_' . $vid))
       ->condition('vid', $vid)
       ->execute();
-    field_attach_create_bundle($machine_name);
+    field_attach_create_bundle('taxonomy_term', $machine_name);
   }
   return $ret;
 }
Index: modules/taxonomy/taxonomy.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v
retrieving revision 1.487
diff -u -r1.487 taxonomy.module
--- modules/taxonomy/taxonomy.module	11 Jul 2009 00:58:52 -0000	1.487
+++ modules/taxonomy/taxonomy.module	18 Jul 2009 02:22:29 -0000
@@ -316,7 +316,7 @@
       }
       $query->execute();
     }
-    field_attach_create_bundle($vocabulary->machine_name);
+    field_attach_create_bundle('taxonomy_term', $vocabulary->machine_name);
     module_invoke_all('taxonomy_vocabulary_insert', $vocabulary);
   }
 
@@ -348,7 +348,7 @@
     taxonomy_term_delete($tid);
   }
 
-  field_attach_delete_bundle($vocabulary['machine_name']);
+  field_attach_delete_bundle('taxonomy_term', $vocabulary['machine_name']);
   module_invoke_all('taxonomy', 'delete', 'vocabulary', $vocabulary);
 
   cache_clear_all();
Index: modules/taxonomy/taxonomy.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.admin.inc,v
retrieving revision 1.62
diff -u -r1.62 taxonomy.admin.inc
--- modules/taxonomy/taxonomy.admin.inc	11 Jul 2009 14:25:41 -0000	1.62
+++ modules/taxonomy/taxonomy.admin.inc	18 Jul 2009 02:22:27 -0000
@@ -241,7 +241,7 @@
   $form_state['values']['nodes'] = array_filter($form_state['values']['nodes']);
   $vocabulary = (object) $form_state['values'];
   if ($vocabulary->machine_name != $old_vocabulary->machine_name) {
-    field_attach_rename_bundle($old_vocabulary->machine_name, $vocabulary->machine_name);
+    field_attach_rename_bundle('taxonomy_term', $old_vocabulary->machine_name, $vocabulary->machine_name);
   }
   switch (taxonomy_vocabulary_save($vocabulary)) {
     case SAVED_NEW:
Index: modules/simpletest/tests/field_test.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/field_test.module,v
retrieving revision 1.13
diff -u -r1.13 field_test.module
--- modules/simpletest/tests/field_test.module	10 Jul 2009 05:58:13 -0000	1.13
+++ modules/simpletest/tests/field_test.module	18 Jul 2009 02:22:27 -0000
@@ -90,18 +90,21 @@
 /**
  * Create a new bundle for test_entity objects.
  *
- * @param $bundle_name
+ * @param $bundle
  *   The machine-readable name of the bundle.
  * @param $text
  *   The human-readable name of the bundle. If none is provided, the machine
  *   name will be used.
  */
-function field_test_create_bundle($bundle_name, $text = NULL) {
+function field_test_create_bundle($bundle, $text = NULL) {
   $bundles = variable_get('field_test_bundles', array('test_bundle' => array('label' => 'Test Bundle')));
-  $bundles += array($bundle_name => array('label' => $text ? $text : $bundle_name));
+  $bundles += array($bundle => array('label' => $text ? $text : $bundle));
   variable_set('field_test_bundles', $bundles);
 
-  field_attach_create_bundle($bundle_name);
+  $info = field_test_fieldable_info();
+  foreach ($info as $type => $type_info) {
+    field_attach_create_bundle($type, $bundle_name);
+  }
 }
 
 /**
@@ -118,21 +121,27 @@
   unset($bundles[$bundle_old]);
   variable_set('field_test_bundles', $bundles);
 
-  field_attach_rename_bundle($bundle_old, $bundle_new);
+  $info = field_test_fieldable_info();
+  foreach ($info as $type => $type_info) {
+    field_attach_rename_bundle($type, $bundle_old, $bundle_new);
+  }
 }
 
 /**
  * Delete a bundle for test_entity objects.
  *
- * @param $bundle_name
+ * @param $bundle
  *   The machine-readable name of the bundle to delete.
  */
-function field_test_delete_bundle($bundle_name) {
+function field_test_delete_bundle($bundle) {
   $bundles = variable_get('field_test_bundles', array('test_bundle' => array('label' => 'Test Bundle')));
-  unset($bundles[$bundle_name]);
+  unset($bundles[$bundle]);
   variable_set('field_test_bundles', $bundles);
 
-  field_attach_delete_bundle($bundle_name);
+  $info = field_test_fieldable_info();
+  foreach ($info as $type => $type_info) {
+    field_attach_delete_bundle($type, $bundle);
+  }
 }
 
 /**
