From cd685741a87189c93a8435496c1163121131d806 Mon Sep 17 00:00:00 2001
From: Bram Goffings <bramgoffings@gmail.com>
Date: Tue, 15 May 2012 19:49:57 +0200
Subject: [PATCH] test remove extract_entity_ids

---
 core/modules/entity/entity.api.php                 |   14 ++---
 core/modules/entity/entity.module                  |   51 ++------------------
 core/modules/field/field.api.php                   |   39 +++++---------
 core/modules/field/field.attach.inc                |   52 +++++++-------------
 core/modules/field/field.default.inc               |    4 +-
 core/modules/field/field.form.inc                  |    2 +-
 core/modules/field/field.module                    |    6 +--
 core/modules/field/field.multilingual.inc          |    9 ++--
 .../field_sql_storage/field_sql_storage.module     |   25 +++------
 .../field/modules/list/tests/list_test.module      |    4 +-
 core/modules/field/tests/field.test                |    3 +-
 core/modules/field/tests/field_test.storage.inc    |   21 +++-----
 core/modules/file/file.field.inc                   |   15 ++----
 core/modules/file/tests/file_module_test.module    |    3 +-
 core/modules/rdf/rdf.module                        |    4 +-
 15 files changed, 76 insertions(+), 176 deletions(-)

diff --git a/core/modules/entity/entity.api.php b/core/modules/entity/entity.api.php
index 8f721cf..3df214b 100644
--- a/core/modules/entity/entity.api.php
+++ b/core/modules/entity/entity.api.php
@@ -254,11 +254,10 @@ function hook_entity_presave($entity, $type) {
 function hook_entity_insert($entity, $type) {
   // Insert the new entity into a fictional table of all entities.
   $info = entity_get_info($type);
-  list($id) = entity_extract_ids($type, $entity);
   db_insert('example_entity')
     ->fields(array(
       'type' => $type,
-      'id' => $id,
+      'id' => $entity->id(),
       'created' => REQUEST_TIME,
       'updated' => REQUEST_TIME,
     ))
@@ -276,13 +275,12 @@ function hook_entity_insert($entity, $type) {
 function hook_entity_update($entity, $type) {
   // Update the entity's entry in a fictional table of all entities.
   $info = entity_get_info($type);
-  list($id) = entity_extract_ids($type, $entity);
   db_update('example_entity')
     ->fields(array(
       'updated' => REQUEST_TIME,
     ))
     ->condition('type', $type)
-    ->condition('id', $id)
+    ->condition('id', $entity->id())
     ->execute();
 }
 
@@ -299,10 +297,9 @@ function hook_entity_update($entity, $type) {
 function hook_entity_predelete($entity, $type) {
   // Count references to this entity in a custom table before they are removed
   // upon entity deletion.
-  list($id) = entity_extract_ids($type, $entity);
   $count = db_select('example_entity_data')
     ->condition('type', $type)
-    ->condition('id', $id)
+    ->condition('id', $entity->id())
     ->countQuery()
     ->execute()
     ->fetchField();
@@ -311,7 +308,7 @@ function hook_entity_predelete($entity, $type) {
   $ref_count_record = (object) array(
     'count' => $count,
     'type' => $type,
-    'id' => $id,
+    'id' => $entity->id(),
   );
   drupal_write_record('example_deleted_entity_statistics', $ref_count_record);
 }
@@ -329,10 +326,9 @@ function hook_entity_predelete($entity, $type) {
 function hook_entity_delete($entity, $type) {
   // Delete the entity's entry from a fictional table of all entities.
   $info = entity_get_info($type);
-  list($id) = entity_extract_ids($type, $entity);
   db_delete('example_entity')
     ->condition('type', $type)
-    ->condition('id', $id)
+    ->condition('id', $entity->id())
     ->execute();
 }
 
diff --git a/core/modules/entity/entity.module b/core/modules/entity/entity.module
index a6599eb..659ac32 100644
--- a/core/modules/entity/entity.module
+++ b/core/modules/entity/entity.module
@@ -122,53 +122,12 @@ function entity_info_cache_clear() {
 }
 
 /**
- * Extracts ID, revision ID, and bundle name from an entity.
- *
- * @param $entity_type
- *   The entity type; e.g. 'node' or 'user'.
- * @param $entity
- *   The entity from which to extract values.
- *
- * @return
- *   A numerically indexed array (not a hash table) containing these
- *   elements:
- *   - 0: Primary ID of the entity.
- *   - 1: Revision ID of the entity, or NULL if $entity_type is not versioned.
- *   - 2: Bundle name of the entity.
- */
-function entity_extract_ids($entity_type, $entity) {
-  $info = entity_get_info($entity_type);
-
-  // Objects being created might not have id/vid yet.
-  $id = isset($entity->{$info['entity keys']['id']}) ? $entity->{$info['entity keys']['id']} : NULL;
-  $vid = ($info['entity keys']['revision'] && isset($entity->{$info['entity keys']['revision']})) ? $entity->{$info['entity keys']['revision']} : NULL;
-
-  if (!empty($info['entity keys']['bundle'])) {
-    // Explicitly fail for malformed entities missing the bundle property.
-    if (!isset($entity->{$info['entity keys']['bundle']}) || $entity->{$info['entity keys']['bundle']} === '') {
-      throw new EntityMalformedException(t('Missing bundle property on entity of type @entity_type.', array('@entity_type' => $entity_type)));
-    }
-    $bundle = $entity->{$info['entity keys']['bundle']};
-  }
-  else {
-    // The entity type provides no bundle key: assume a single bundle, named
-    // after the entity type.
-    $bundle = $entity_type;
-  }
-
-  return array($id, $vid, $bundle);
-}
-
-/**
  * Assembles an object structure with initial IDs.
  *
- * This function can be seen as reciprocal to entity_extract_ids().
- *
  * @param $entity_type
  *   The entity type; e.g. 'node' or 'user'.
  * @param $ids
- *   A numerically indexed array, as returned by entity_extract_ids(),
- *   containing these elements:
+ *   A numerically indexed array containing these elements:
  *   - 0: Primary ID of the entity.
  *   - 1: Revision ID of the entity, or NULL if $entity_type is not versioned.
  *   - 2: Bundle name of the entity, or NULL if $entity_type has no bundles.
@@ -382,12 +341,11 @@ function entity_prepare_view($entity_type, $entities) {
  */
 function entity_uri($entity_type, $entity) {
   $info = entity_get_info($entity_type);
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
 
   // A bundle-specific callback takes precedence over the generic one for the
   // entity type.
-  if (isset($info['bundles'][$bundle]['uri callback'])) {
-    $uri_callback = $info['bundles'][$bundle]['uri callback'];
+  if (isset($info['bundles'][$entity->bundle()]['uri callback'])) {
+    $uri_callback = $info['bundles'][$entity->bundle()]['uri callback'];
   }
   elseif (isset($info['uri callback'])) {
     $uri_callback = $info['uri callback'];
@@ -473,12 +431,11 @@ function entity_form_field_validate($entity_type, $form, &$form_state) {
  */
 function entity_form_submit_build_entity($entity_type, $entity, $form, &$form_state) {
   $info = entity_get_info($entity_type);
-  list(, , $bundle) = entity_extract_ids($entity_type, $entity);
 
   // Copy top-level form values that are not for fields to entity properties,
   // without changing existing entity properties that are not being edited by
   // this form. Copying field values must be done using field_attach_submit().
-  $values_excluding_fields = $info['fieldable'] ? array_diff_key($form_state['values'], field_info_instances($entity_type, $bundle)) : $form_state['values'];
+  $values_excluding_fields = $info['fieldable'] ? array_diff_key($form_state['values'], field_info_instances($entity_type, $entity->bundle())) : $form_state['values'];
   foreach ($values_excluding_fields as $key => $value) {
     $entity->$key = $value;
   }
diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php
index 44aa50b..a8f6536 100644
--- a/core/modules/field/field.api.php
+++ b/core/modules/field/field.api.php
@@ -584,15 +584,14 @@ function hook_field_storage_update_field($field, $prior_field, $has_data) {
  * @see hook_field_update()
  */
 function hook_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) {
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
   foreach ($items as $delta => $item) {
     // For hook_file_references(), remember that this is being deleted.
     $item['file_field_name'] = $field['field_name'];
     // Pass in the ID of the object that is being removed so all references can
     // be counted in hook_file_references().
     $item['file_field_type'] = $entity_type;
-    $item['file_field_id'] = $id;
-    file_field_delete_file($item, $field, $entity_type, $id);
+    $item['file_field_id'] = $entity->id();
+    file_field_delete_file($item, $field, $entity_type, $entity->id());
   }
 }
 
@@ -617,11 +616,10 @@ function hook_field_delete($entity_type, $entity, $field, $instance, $langcode,
  *   $entity->{$field['field_name']}[$langcode], or an empty array if unset.
  */
 function hook_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, &$items) {
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
   foreach ($items as $delta => $item) {
     // For hook_file_references, remember that this file is being deleted.
     $item['file_field_name'] = $field['field_name'];
-    if (file_field_delete_file($item, $field, $entity_type, $id)) {
+    if (file_field_delete_file($item, $field, $entity_type, $entity->id())) {
       $items[$delta] = NULL;
     }
   }
@@ -1762,10 +1760,7 @@ function hook_field_storage_load($entity_type, $entities, $age, $fields, $option
  *   array are field IDs.
  */
 function hook_field_storage_write($entity_type, $entity, $op, $fields) {
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-  if (!isset($vid)) {
-    $vid = $id;
-  }
+  $vid = isset($entity->vid) ? $entity->vid : $entity->id();
 
   foreach ($fields as $field_id) {
     $field = field_info_field_by_id($field_id);
@@ -1784,12 +1779,12 @@ function hook_field_storage_write($entity_type, $entity, $op, $fields) {
       if ($langcodes) {
         db_delete($table_name)
           ->condition('entity_type', $entity_type)
-          ->condition('entity_id', $id)
+          ->condition('entity_id', $entity->id())
           ->condition('langcode', $langcodes, 'IN')
           ->execute();
         db_delete($revision_name)
           ->condition('entity_type', $entity_type)
-          ->condition('entity_id', $id)
+          ->condition('entity_id', $entity->id())
           ->condition('revision_id', $vid)
           ->condition('langcode', $langcodes, 'IN')
           ->execute();
@@ -1813,9 +1808,9 @@ function hook_field_storage_write($entity_type, $entity, $op, $fields) {
         $do_insert = TRUE;
         $record = array(
           'entity_type' => $entity_type,
-          'entity_id' => $id,
+          'entity_id' => $entity->id(),
           'revision_id' => $vid,
-          'bundle' => $bundle,
+          'bundle' => $entity->bundle(),
           'delta' => $delta,
           'langcode' => $langcode,
         );
@@ -1856,9 +1851,7 @@ function hook_field_storage_write($entity_type, $entity, $op, $fields) {
  *   array are field IDs.
  */
 function hook_field_storage_delete($entity_type, $entity, $fields) {
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-
-  foreach (field_info_instances($entity_type, $bundle) as $instance) {
+  foreach (field_info_instances($entity_type, $entity->bundle()) as $instance) {
     if (isset($fields[$instance['field_id']])) {
       $field = field_info_field_by_id($instance['field_id']);
       field_sql_storage_field_storage_purge($entity_type, $entity, $field, $instance);
@@ -1886,16 +1879,14 @@ function hook_field_storage_delete($entity_type, $entity, $fields) {
  *   array are field IDs.
  */
 function hook_field_storage_delete_revision($entity_type, $entity, $fields) {
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-
-  if (isset($vid)) {
+  if (isset($entity->vid)) {
     foreach ($fields as $field_id) {
       $field = field_info_field_by_id($field_id);
       $revision_name = _field_sql_storage_revision_tablename($field);
       db_delete($revision_name)
         ->condition('entity_type', $entity_type)
-        ->condition('entity_id', $id)
-        ->condition('revision_id', $vid)
+        ->condition('entity_id', $entity->id())
+        ->condition('revision_id', $entity->vid)
         ->execute();
     }
   }
@@ -2631,17 +2622,15 @@ function hook_field_storage_purge_field_instance($instance) {
  *   The deleted field instance whose data is being purged.
  */
 function hook_field_storage_purge($entity_type, $entity, $field, $instance) {
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-
   $table_name = _field_sql_storage_tablename($field);
   $revision_name = _field_sql_storage_revision_tablename($field);
   db_delete($table_name)
     ->condition('entity_type', $entity_type)
-    ->condition('entity_id', $id)
+    ->condition('entity_id', $entity->id())
     ->execute();
   db_delete($revision_name)
     ->condition('entity_type', $entity_type)
-    ->condition('entity_id', $id)
+    ->condition('entity_id', $entity->id())
     ->execute();
 }
 
diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc
index cf597f0..88a9565 100644
--- a/core/modules/field/field.attach.inc
+++ b/core/modules/field/field.attach.inc
@@ -166,8 +166,7 @@ function _field_invoke($op, $entity_type, $entity, &$a = NULL, &$b = NULL, $opti
   $options += $default_options;
 
   // Determine the list of instances to iterate on.
-  list(, , $bundle) = entity_extract_ids($entity_type, $entity);
-  $instances = _field_invoke_get_instances($entity_type, $bundle, $options);
+  $instances = _field_invoke_get_instances($entity_type, $entity->bundle(), $options);
 
   // Iterate through the instances and collect results.
   $return = array();
@@ -279,8 +278,7 @@ function _field_invoke_multiple($op, $entity_type, $entities, &$a = NULL, &$b =
   // $entity->$field_name property.
   foreach ($entities as $entity) {
     // Determine the list of instances to iterate on.
-    list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-    $instances = _field_invoke_get_instances($entity_type, $bundle, $options);
+    $instances = _field_invoke_get_instances($entity_type, $entity->bundle(), $options);
 
     foreach ($instances as $instance) {
       $field_id = $instance['field_id'];
@@ -297,19 +295,19 @@ function _field_invoke_multiple($op, $entity_type, $entities, &$a = NULL, &$b =
         // Unless a language code suggestion is provided we iterate on all the
         // available language codes.
         $available_langcodes = field_available_languages($entity_type, $field);
-        $langcode = !empty($options['langcode'][$id]) ? $options['langcode'][$id] : $options['langcode'];
+        $langcode = !empty($options['langcode'][$entity->id()]) ? $options['langcode'][$entity->id()] : $options['langcode'];
         $langcodes = _field_language_suggestion($available_langcodes, $langcode, $field_name);
         foreach ($langcodes as $langcode) {
-          $grouped_items[$field_id][$langcode][$id] = isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : array();
+          $grouped_items[$field_id][$langcode][$entity->id()] = isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : array();
           // Group the instances and entities corresponding to the current
           // field.
-          $grouped_instances[$field_id][$langcode][$id] = $instance;
-          $grouped_entities[$field_id][$langcode][$id] = $entities[$id];
+          $grouped_instances[$field_id][$langcode][$entity->id()] = $instance;
+          $grouped_entities[$field_id][$langcode][$entity->id()] = $entities[$entity->id()];
         }
       }
     }
     // Initialize the return value for each entity.
-    $return[$id] = array();
+    $return[$entity->id()] = array();
   }
 
   // For each field, invoke the field hook and collect results.
@@ -546,10 +544,9 @@ function field_attach_form($entity_type, $entity, &$form, &$form_state, $langcod
   $form += (array) _field_invoke_default('form', $entity_type, $entity, $form, $form_state, $options);
 
   // Add custom weight handling.
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
   $form['#pre_render'][] = '_field_extra_fields_pre_render';
   $form['#entity_type'] = $entity_type;
-  $form['#bundle'] = $bundle;
+  $form['#bundle'] = $entity->bundle();
 
   // Let other modules make changes to the form.
   // Avoid module_invoke_all() to let parameters be taken by reference.
@@ -658,15 +655,14 @@ function field_attach_load($entity_type, $entities, $age = FIELD_LOAD_CURRENT, $
     // Collect the storage backends used by the remaining fields in the entities.
     $storages = array();
     foreach ($queried_entities as $entity) {
-      list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-      $instances = _field_invoke_get_instances($entity_type, $bundle, $options);
+      $instances = _field_invoke_get_instances($entity_type, $entity->bundle(), $options);
 
       foreach ($instances as $instance) {
         $field_name = $instance['field_name'];
         $field_id = $instance['field_id'];
         // Make sure all fields are present at least as empty arrays.
-        if (!isset($queried_entities[$id]->{$field_name})) {
-          $queried_entities[$id]->{$field_name} = array();
+        if (!isset($queried_entities[$entity->id()]->{$field_name})) {
+          $queried_entities[$entity->id()]->{$field_name} = array();
         }
         // Collect the storage backend if the field has not been loaded yet.
         if (!isset($skip_fields[$field_id])) {
@@ -694,8 +690,7 @@ function field_attach_load($entity_type, $entities, $age = FIELD_LOAD_CURRENT, $
     if ($cache_write) {
       foreach ($queried_entities as $id => $entity) {
         $data = array();
-        list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-        $instances = field_info_instances($entity_type, $bundle);
+        $instances = field_info_instances($entity_type, $entity->bundle());
         foreach ($instances as $instance) {
           $data[$instance['field_name']] = $queried_entities[$id]->{$instance['field_name']};
         }
@@ -888,8 +883,6 @@ function field_attach_insert($entity_type, $entity) {
   _field_invoke_default('insert', $entity_type, $entity);
   _field_invoke('insert', $entity_type, $entity);
 
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-
   // Let any module insert field data before the storage engine, accumulating
   // saved fields along the way.
   $skip_fields = array();
@@ -900,7 +893,7 @@ function field_attach_insert($entity_type, $entity) {
 
   // Collect the storage backends used by the remaining fields in the entities.
   $storages = array();
-  foreach (field_info_instances($entity_type, $bundle) as $instance) {
+  foreach (field_info_instances($entity_type, $entity->bundle()) as $instance) {
     $field = field_info_field_by_id($instance['field_id']);
     $field_id = $field['id'];
     $field_name = $field['field_name'];
@@ -935,8 +928,6 @@ function field_attach_insert($entity_type, $entity) {
 function field_attach_update($entity_type, $entity) {
   _field_invoke('update', $entity_type, $entity);
 
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-
   // Let any module update field data before the storage engine, accumulating
   // saved fields along the way.
   $skip_fields = array();
@@ -947,7 +938,7 @@ function field_attach_update($entity_type, $entity) {
 
   // Collect the storage backends used by the remaining fields in the entities.
   $storages = array();
-  foreach (field_info_instances($entity_type, $bundle) as $instance) {
+  foreach (field_info_instances($entity_type, $entity->bundle()) as $instance) {
     $field = field_info_field_by_id($instance['field_id']);
     $field_id = $field['id'];
     $field_name = $field['field_name'];
@@ -990,11 +981,9 @@ function field_attach_update($entity_type, $entity) {
 function field_attach_delete($entity_type, $entity) {
   _field_invoke('delete', $entity_type, $entity);
 
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-
   // Collect the storage backends used by the fields in the entities.
   $storages = array();
-  foreach (field_info_instances($entity_type, $bundle) as $instance) {
+  foreach (field_info_instances($entity_type, $entity->bundle()) as $instance) {
     $field = field_info_field_by_id($instance['field_id']);
     $field_id = $field['id'];
     $storages[$field['storage']['type']][$field_id] = $field_id;
@@ -1027,11 +1016,9 @@ function field_attach_delete($entity_type, $entity) {
 function field_attach_delete_revision($entity_type, $entity) {
   _field_invoke('delete_revision', $entity_type, $entity);
 
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-
   // Collect the storage backends used by the fields in the entities.
   $storages = array();
-  foreach (field_info_instances($entity_type, $bundle) as $instance) {
+  foreach (field_info_instances($entity_type, $entity->bundle()) as $instance) {
     $field = field_info_field_by_id($instance['field_id']);
     $field_id = $field['id'];
     $storages[$field['storage']['type']][$field_id] = $field_id;
@@ -1159,10 +1146,9 @@ function field_attach_view($entity_type, $entity, $view_mode, $langcode = NULL)
   $output = _field_invoke_default('view', $entity_type, $entity, $view_mode, $null, $options);
 
   // Add custom weight handling.
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
   $output['#pre_render'][] = '_field_extra_fields_pre_render';
   $output['#entity_type'] = $entity_type;
-  $output['#bundle'] = $bundle;
+  $output['#bundle'] = $entity->bundle();
 
   // Let other modules alter the renderable array.
   $context = array(
@@ -1201,9 +1187,7 @@ function field_attach_view($entity_type, $entity, $view_mode, $langcode = NULL)
  *   values.
  */
 function field_attach_preprocess($entity_type, $entity, $element, &$variables) {
-  list(, , $bundle) = entity_extract_ids($entity_type, $entity);
-
-  foreach (field_info_instances($entity_type, $bundle) as $instance) {
+  foreach (field_info_instances($entity_type, $entity->bundle()) as $instance) {
     $field_name = $instance['field_name'];
     if (isset($element[$field_name]['#language'])) {
       $langcode = $element[$field_name]['#language'];
diff --git a/core/modules/field/field.default.inc b/core/modules/field/field.default.inc
index 1e1675c..b4a6f50 100644
--- a/core/modules/field/field.default.inc
+++ b/core/modules/field/field.default.inc
@@ -189,8 +189,6 @@ function field_default_prepare_view($entity_type, $entities, $field, $instances,
  *     of $instance definitions.
  */
 function field_default_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-
   $addition = array();
 
   // Prepare incoming display specifications.
@@ -222,7 +220,7 @@ function field_default_view($entity_type, $entity, $field, $instance, $langcode,
           '#field_type' => $field['type'],
           '#field_translatable' => $field['translatable'],
           '#entity_type' => $entity_type,
-          '#bundle' => $bundle,
+          '#bundle' => $entity->bundle(),
           '#object' => $entity,
           '#items' => $items,
           '#formatter' => $display['type']
diff --git a/core/modules/field/field.form.inc b/core/modules/field/field.form.inc
index 2ced5b0..e6b7366 100644
--- a/core/modules/field/field.form.inc
+++ b/core/modules/field/field.form.inc
@@ -12,7 +12,7 @@ function field_default_form($entity_type, $entity, $field, $instance, $langcode,
   // This could be called with no entity, as when a UI module creates a
   // dummy form to set default values.
   if ($entity) {
-    list($id, , ) = entity_extract_ids($entity_type, $entity);
+    $id = $entity->id();
   }
 
   $parents = $form['#parents'];
diff --git a/core/modules/field/field.module b/core/modules/field/field.module
index ab67eb2..1475b98 100644
--- a/core/modules/field/field.module
+++ b/core/modules/field/field.module
@@ -887,12 +887,10 @@ function field_view_field($entity_type, $entity, $field_name, $display = array()
 
     // Invoke prepare_view steps if needed.
     if (empty($entity->_field_view_prepared)) {
-      list($id) = entity_extract_ids($entity_type, $entity);
-
       // First let the field types do their preparation.
-      _field_invoke_multiple('prepare_view', $entity_type, array($id => $entity), $display, $null, $options);
+      _field_invoke_multiple('prepare_view', $entity_type, array($entity->id() => $entity), $display, $null, $options);
       // Then let the formatters do their own specific massaging.
-      _field_invoke_multiple_default('prepare_view', $entity_type, array($id => $entity), $display, $null, $options);
+      _field_invoke_multiple_default('prepare_view', $entity_type, array($entity->id() => $entity), $display, $null, $options);
     }
 
     // Build the renderable array.
diff --git a/core/modules/field/field.multilingual.inc b/core/modules/field/field.multilingual.inc
index f054bf1..2ce768d 100644
--- a/core/modules/field/field.multilingual.inc
+++ b/core/modules/field/field.multilingual.inc
@@ -285,16 +285,15 @@ function field_valid_language($langcode, $default = TRUE) {
  */
 function field_language($entity_type, $entity, $field_name = NULL, $langcode = NULL) {
   $display_langcodes = &drupal_static(__FUNCTION__, array());
-  list($id, , $bundle) = entity_extract_ids($entity_type, $entity);
   $langcode = field_valid_language($langcode, FALSE);
 
-  if (!isset($display_langcodes[$entity_type][$id][$langcode])) {
+  if (!isset($display_langcodes[$entity_type][$entity->id()][$langcode])) {
     $display_langcode = array();
 
     // By default display language is set to LANGUAGE_NOT_SPECIFIED if the field
     // translation is not available. It is up to translation handlers to
     // implement language fallback rules.
-    foreach (field_info_instances($entity_type, $bundle) as $instance) {
+    foreach (field_info_instances($entity_type, $entity->bundle()) as $instance) {
       $display_langcode[$instance['field_name']] = isset($entity->{$instance['field_name']}[$langcode]) ? $langcode : LANGUAGE_NOT_SPECIFIED;
     }
 
@@ -307,10 +306,10 @@ function field_language($entity_type, $entity, $field_name = NULL, $langcode = N
       drupal_alter('field_language', $display_langcode, $context);
     }
 
-    $display_langcodes[$entity_type][$id][$langcode] = $display_langcode;
+    $display_langcodes[$entity_type][$entity->id()][$langcode] = $display_langcode;
   }
 
-  $display_langcode = $display_langcodes[$entity_type][$id][$langcode];
+  $display_langcode = $display_langcodes[$entity_type][$entity->id()][$langcode];
 
   // Single-field mode.
   if (isset($field_name)) {
diff --git a/core/modules/field/modules/field_sql_storage/field_sql_storage.module b/core/modules/field/modules/field_sql_storage/field_sql_storage.module
index f9c27a8..8bb1bc3 100644
--- a/core/modules/field/modules/field_sql_storage/field_sql_storage.module
+++ b/core/modules/field/modules/field_sql_storage/field_sql_storage.module
@@ -376,10 +376,7 @@ function field_sql_storage_field_storage_load($entity_type, $entities, $age, $fi
  * Implements hook_field_storage_write().
  */
 function field_sql_storage_field_storage_write($entity_type, $entity, $op, $fields) {
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-  if (!isset($vid)) {
-    $vid = $id;
-  }
+  $vid = isset($entity->vid) ? $entity->vid : $entity->id();
 
   foreach ($fields as $field_id) {
     $field = field_info_field_by_id($field_id);
@@ -429,7 +426,7 @@ function field_sql_storage_field_storage_write($entity_type, $entity, $op, $fiel
           'entity_type' => $entity_type,
           'entity_id' => $id,
           'revision_id' => $vid,
-          'bundle' => $bundle,
+          'bundle' => $entity->bundle(),
           'delta' => $delta,
           'langcode' => $langcode,
         );
@@ -461,9 +458,7 @@ function field_sql_storage_field_storage_write($entity_type, $entity, $op, $fiel
  * This function deletes data for all fields for an entity from the database.
  */
 function field_sql_storage_field_storage_delete($entity_type, $entity, $fields) {
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-
-  foreach (field_info_instances($entity_type, $bundle) as $instance) {
+  foreach (field_info_instances($entity_type, $entity->bundle()) as $instance) {
     if (isset($fields[$instance['field_id']])) {
       $field = field_info_field_by_id($instance['field_id']);
       field_sql_storage_field_storage_purge($entity_type, $entity, $field, $instance);
@@ -478,17 +473,15 @@ function field_sql_storage_field_storage_delete($entity_type, $entity, $fields)
  * an entity.
  */
 function field_sql_storage_field_storage_purge($entity_type, $entity, $field, $instance) {
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-
   $table_name = _field_sql_storage_tablename($field);
   $revision_name = _field_sql_storage_revision_tablename($field);
   db_delete($table_name)
     ->condition('entity_type', $entity_type)
-    ->condition('entity_id', $id)
+    ->condition('entity_id', $entity->id())
     ->execute();
   db_delete($revision_name)
     ->condition('entity_type', $entity_type)
-    ->condition('entity_id', $id)
+    ->condition('entity_id', $entity->id())
     ->execute();
 }
 
@@ -653,16 +646,14 @@ function _field_sql_storage_query_field_conditions(EntityFieldQuery $query, Sele
  * This function actually deletes the data from the database.
  */
 function field_sql_storage_field_storage_delete_revision($entity_type, $entity, $fields) {
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-
-  if (isset($vid)) {
+  if (isset($entity->$vid)) {
     foreach ($fields as $field_id) {
       $field = field_info_field_by_id($field_id);
       $revision_name = _field_sql_storage_revision_tablename($field);
       db_delete($revision_name)
         ->condition('entity_type', $entity_type)
-        ->condition('entity_id', $id)
-        ->condition('revision_id', $vid)
+        ->condition('entity_id', $entity->id)
+        ->condition('revision_id', $entity->vid)
         ->execute();
     }
   }
diff --git a/core/modules/field/modules/list/tests/list_test.module b/core/modules/field/modules/list/tests/list_test.module
index aa53337..a244770 100644
--- a/core/modules/field/modules/list/tests/list_test.module
+++ b/core/modules/field/modules/list/tests/list_test.module
@@ -27,6 +27,8 @@ function list_test_allowed_values_callback($field) {
  */
 function list_test_dynamic_values_callback($field, $instance, $entity_type, $entity, &$cacheable) {
   $cacheable = FALSE;
+  $vid = isset($entity->vid) ? $entity->vid : null;
+
   // We need the values of the entity as keys.
-  return drupal_map_assoc(array_merge(array($entity->ftlabel), entity_extract_ids($entity_type, $entity)));
+  return drupal_map_assoc(array($entity->ftlabel, $entity->id, $vid, $entity->bundle));
 }
diff --git a/core/modules/field/tests/field.test b/core/modules/field/tests/field.test
index 9a850d9..a88a032 100644
--- a/core/modules/field/tests/field.test
+++ b/core/modules/field/tests/field.test
@@ -3077,7 +3077,8 @@ class FieldBulkDeleteTestCase extends FieldTestCase {
   function _generateStubEntities($entity_type, $entities, $field_name = NULL) {
     $stubs = array();
     foreach ($entities as $id => $entity) {
-      $stub = entity_create_stub_entity($entity_type, entity_extract_ids($entity_type, $entity));
+      $vid = isset($entity->vid) ? $entity->vid : null;
+      $stub = entity_create_stub_entity($entity_type, array($entity->id, $vid, $entity->bundle));
       if (isset($field_name)) {
         $stub->{$field_name} = $entity->{$field_name};
       }
diff --git a/core/modules/field/tests/field_test.storage.inc b/core/modules/field/tests/field_test.storage.inc
index eaa0851..21cb78e 100644
--- a/core/modules/field/tests/field_test.storage.inc
+++ b/core/modules/field/tests/field_test.storage.inc
@@ -118,8 +118,7 @@ function field_test_field_storage_load($entity_type, $entities, $age, $fields, $
  */
 function field_test_field_storage_write($entity_type, $entity, $op, $fields) {
   $data = _field_test_storage_data();
-
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
+  $vid = isset($entity->vid) ? $entity->vid : null;
 
   foreach ($fields as $field_id) {
     $field = field_info_field_by_id($field_id);
@@ -136,7 +135,7 @@ function field_test_field_storage_write($entity_type, $entity, $op, $fields) {
       $langcodes = !empty($entity->$field_name) ? $field_langcodes : $all_langcodes;
       if ($langcodes) {
         foreach ($field_data['current'] as $key => $row) {
-          if ($row->type == $entity_type && $row->entity_id == $id && in_array($row->langcode, $langcodes)) {
+          if ($row->type == $entity_type && $row->entity_id == $entity->id() && in_array($row->langcode, $langcodes)) {
             unset($field_data['current'][$key]);
           }
         }
@@ -157,9 +156,9 @@ function field_test_field_storage_write($entity_type, $entity, $op, $fields) {
         $row = (object) array(
           'field_id' => $field_id,
           'type' => $entity_type,
-          'entity_id' => $id,
+          'entity_id' => $entity->id(),
           'revision_id' => $vid,
-          'bundle' => $bundle,
+          'bundle' => $entity->bundle(),
           'delta' => $delta,
           'deleted' => FALSE,
           'langcode' => $langcode,
@@ -187,11 +186,9 @@ function field_test_field_storage_write($entity_type, $entity, $op, $fields) {
  * Implements hook_field_storage_delete().
  */
 function field_test_field_storage_delete($entity_type, $entity, $fields) {
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-
   // Note: reusing field_test_storage_purge(), like field_sql_storage.module
   // does, is highly inefficient in our case...
-  foreach (field_info_instances($bundle) as $instance) {
+  foreach (field_info_instances($entity->bundle()) as $instance) {
     if (isset($fields[$instance['field_id']])) {
       $field = field_info_field_by_id($instance['field_id']);
       field_test_field_storage_purge($entity_type, $entity, $field, $instance);
@@ -205,12 +202,10 @@ function field_test_field_storage_delete($entity_type, $entity, $fields) {
 function field_test_field_storage_purge($entity_type, $entity, $field, $instance) {
   $data = _field_test_storage_data();
 
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-
   $field_data = &$data[$field['id']];
   foreach (array('current', 'revisions') as $sub_table) {
     foreach ($field_data[$sub_table] as $key => $row) {
-      if ($row->type == $entity_type && $row->entity_id == $id) {
+      if ($row->type == $entity_type && $row->entity_id == $entity->id()) {
         unset($field_data[$sub_table][$key]);
       }
     }
@@ -224,13 +219,13 @@ function field_test_field_storage_purge($entity_type, $entity, $field, $instance
  */
 function field_test_field_storage_delete_revision($entity_type, $entity, $fields) {
   $data = _field_test_storage_data();
+  $vid = isset($entity->vid) ? $entity->vid : null;
 
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
   foreach ($fields as $field_id) {
     $field_data = &$data[$field_id];
     foreach (array('current', 'revisions') as $sub_table) {
       foreach ($field_data[$sub_table] as $key => $row) {
-        if ($row->type == $entity_type && $row->entity_id == $id && $row->revision_id == $vid) {
+        if ($row->type == $entity_type && $row->entity_id == $entity->id() && $row->revision_id == $vid) {
           unset($field_data[$sub_table][$key]);
         }
       }
diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc
index a1a2ef9..014aa67 100644
--- a/core/modules/file/file.field.inc
+++ b/core/modules/file/file.field.inc
@@ -239,12 +239,10 @@ function file_field_presave($entity_type, $entity, $field, $instance, $langcode,
  * Implements hook_field_insert().
  */
 function file_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-
   // Add a new usage of each uploaded file.
   foreach ($items as $item) {
     $file = (object) $item;
-    file_usage_add($file, 'file', $entity_type, $id);
+    file_usage_add($file, 'file', $entity_type, $entity->id());
   }
 }
 
@@ -254,14 +252,12 @@ function file_field_insert($entity_type, $entity, $field, $instance, $langcode,
  * Checks for files that have been removed from the object.
  */
 function file_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) {
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-
   // On new revisions, all files are considered to be a new usage and no
   // deletion of previous file usages are necessary.
   if (!empty($entity->revision)) {
     foreach ($items as $item) {
       $file = (object) $item;
-      file_usage_add($file, 'file', $entity_type, $id);
+      file_usage_add($file, 'file', $entity_type, $entity->id());
     }
     return;
   }
@@ -301,11 +297,9 @@ function file_field_update($entity_type, $entity, $field, $instance, $langcode,
  * Implements hook_field_delete().
  */
 function file_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) {
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
-
   // Delete all file usages within this entity.
   foreach ($items as $delta => $item) {
-    file_field_delete_file($item, $field, $entity_type, $id, 0);
+    file_field_delete_file($item, $field, $entity_type, $entity->id());
   }
 }
 
@@ -313,10 +307,9 @@ function file_field_delete($entity_type, $entity, $field, $instance, $langcode,
  * Implements hook_field_delete_revision().
  */
 function file_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, &$items) {
-  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
   foreach ($items as $delta => $item) {
     // Decrement the file usage count by 1 and delete the file if possible.
-    if (file_field_delete_file($item, $field, $entity_type, $id)) {
+    if (file_field_delete_file($item, $field, $entity_type, $entity->id())) {
       $items[$delta] = NULL;
     }
   }
diff --git a/core/modules/file/tests/file_module_test.module b/core/modules/file/tests/file_module_test.module
index 490ef42..216b10f 100644
--- a/core/modules/file/tests/file_module_test.module
+++ b/core/modules/file/tests/file_module_test.module
@@ -73,8 +73,7 @@ function file_module_test_form_submit($form, &$form_state) {
  * Implements hook_file_download_access().
  */
 function file_module_test_file_download_access($field, $entity_type, $entity) {
-  list(,, $bundle) = entity_extract_ids($entity_type, $entity);
-  $instance = field_info_instance($entity_type, $field['field_name'], $bundle);
+  $instance = field_info_instance($entity_type, $field['field_name'], $entity->bundle());
   // Allow the file to be downloaded only if the given arguments are correct.
   // If any are wrong, $instance will be NULL.
   if (empty($instance)) {
diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module
index 43ee4ed..b92736f 100644
--- a/core/modules/rdf/rdf.module
+++ b/core/modules/rdf/rdf.module
@@ -388,9 +388,7 @@ function rdf_entity_info_alter(&$entity_info) {
  */
 function rdf_entity_load($entities, $type) {
   foreach ($entities as $entity) {
-    // Extracts the bundle of the entity being loaded.
-    list($id, $vid, $bundle) = entity_extract_ids($type, $entity);
-    $entity->rdf_mapping = rdf_mapping_load($type, $bundle);
+    $entity->rdf_mapping = rdf_mapping_load($type, $entity->bundle());
   }
 }
 
-- 
1.7.4.msysgit.0

