From 60a117f1b73aa33aad590c6d85567a66e75a42b2 Mon Sep 17 00:00:00 2001
From: Bram Goffings <bramgoffings@gmail.com>
Date: Sun, 17 Jun 2012 16:38:43 +0200
Subject: [PATCH] remove entity_extract_ids

---
 core/modules/entity/entity.api.php                 |    2 +-
 core/modules/entity/entity.module                  |   51 ++------------------
 core/modules/field/field.api.php                   |   40 ++++++---------
 core/modules/field/field.attach.inc                |   43 +++++-----------
 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          |    4 +-
 .../lib/Drupal/field/Tests/BulkDeleteTest.php      |    2 +-
 .../field_sql_storage/field_sql_storage.module     |   25 +++-------
 .../field/modules/list/tests/list_test.module      |    2 +-
 .../modules/field_test/field_test.storage.inc      |   22 +++------
 core/modules/file/file.field.inc                   |   19 ++-----
 core/modules/file/tests/file_module_test.module    |    3 +-
 core/modules/rdf/rdf.module                        |    4 +-
 15 files changed, 66 insertions(+), 163 deletions(-)

diff --git a/core/modules/entity/entity.api.php b/core/modules/entity/entity.api.php
index 02d8754..135ea30 100644
--- a/core/modules/entity/entity.api.php
+++ b/core/modules/entity/entity.api.php
@@ -305,7 +305,7 @@ function hook_entity_predelete(Drupal\entity\EntityInterface $entity) {
   $ref_count_record = (object) array(
     'count' => $count,
     'type' => $type,
-    'id' => $id,
+    'id' => $entity->id(),
   );
   drupal_write_record('example_deleted_entity_statistics', $ref_count_record);
 }
diff --git a/core/modules/entity/entity.module b/core/modules/entity/entity.module
index a66b1e8..505d43f 100644
--- a/core/modules/entity/entity.module
+++ b/core/modules/entity/entity.module
@@ -125,53 +125,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.
@@ -386,12 +345,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'];
@@ -469,12 +427,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 455ecc2..8dbc60c 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,9 +1760,9 @@ 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 = $entity->getRevisionId();
+  if(!isset($vid)) {
+    $vid = $entity->id();
   }
 
   foreach ($fields as $field_id) {
@@ -1784,12 +1782,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 +1811,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 +1854,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 +1882,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->getRevisionId())) {
     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->getRevisionId())
         ->execute();
     }
   }
@@ -2631,17 +2625,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 e4b28a9..fd8bfe5 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,8 @@ 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);
+    $id = $entity->id();
 
     foreach ($instances as $instance) {
       $field_id = $instance['field_id'];
@@ -546,10 +545,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 +656,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 +691,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 +884,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 +894,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 +929,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 +939,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 +982,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 +1017,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 +1147,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 +1188,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 4cf953d..6a9b9cc 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 822e802..3aa33ca 100644
--- a/core/modules/field/field.module
+++ b/core/modules/field/field.module
@@ -914,12 +914,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 30c1e41..1d89e3a 100644
--- a/core/modules/field/field.multilingual.inc
+++ b/core/modules/field/field.multilingual.inc
@@ -295,7 +295,7 @@ 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);
+  $id  = $entity->id();
   $langcode = field_valid_language($langcode, FALSE);
 
   if (!isset($display_langcodes[$entity_type][$id][$langcode])) {
@@ -304,7 +304,7 @@ function field_language($entity_type, $entity, $field_name = NULL, $langcode = N
     // By default, display language is set to one of the locked languages
     // 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) {
       if (isset($entity->{$instance['field_name']}[$langcode])) {
         $display_langcode[$instance['field_name']] = $langcode;
       }
diff --git a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php
index 347f55c..907f248 100644
--- a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php
+++ b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php
@@ -44,7 +44,7 @@ class BulkDeleteTest extends FieldTestBase {
   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));
+      $stub = entity_create_stub_entity($entity_type, $entity->id(), $entity->getRevisionId(), $entity->bundle());
       if (isset($field_name)) {
         $stub->{$field_name} = $entity->{$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 fd2f52c..ba39f74 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
@@ -378,10 +378,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->getRevisionId()) ? $entity->getRevisionId() : $entity->id();
 
   foreach ($fields as $field_id) {
     $field = field_info_field_by_id($field_id);
@@ -431,7 +428,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,
         );
@@ -463,9 +460,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);
@@ -480,17 +475,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();
 }
 
@@ -655,16 +648,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->$getRevisionId()) {
     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->getRevisionId())
         ->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..94f81b8 100644
--- a/core/modules/field/modules/list/tests/list_test.module
+++ b/core/modules/field/modules/list/tests/list_test.module
@@ -28,5 +28,5 @@ function list_test_allowed_values_callback($field) {
 function list_test_dynamic_values_callback($field, $instance, $entity_type, $entity, &$cacheable) {
   $cacheable = FALSE;
   // 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(), $entity->getRevisionId(), $entity->bundle()));
 }
diff --git a/core/modules/field/tests/modules/field_test/field_test.storage.inc b/core/modules/field/tests/modules/field_test/field_test.storage.inc
index eaa0851..f9382a4 100644
--- a/core/modules/field/tests/modules/field_test/field_test.storage.inc
+++ b/core/modules/field/tests/modules/field_test/field_test.storage.inc
@@ -82,7 +82,6 @@ function _field_test_storage_data($data = NULL) {
  */
 function field_test_field_storage_load($entity_type, $entities, $age, $fields, $options) {
   $data = _field_test_storage_data();
-
   $load_current = $age == FIELD_LOAD_CURRENT;
 
   foreach ($fields as $field_id => $ids) {
@@ -119,8 +118,6 @@ 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);
-
   foreach ($fields as $field_id) {
     $field = field_info_field_by_id($field_id);
     $field_name = $field['field_name'];
@@ -136,7 +133,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 +154,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,
-          'revision_id' => $vid,
-          'bundle' => $bundle,
+          'entity_id' => $entity->id(),
+          'revision_id' => $entity->getRevisionId(),
+          'bundle' => $entity->bundle(),
           'delta' => $delta,
           'deleted' => FALSE,
           'langcode' => $langcode,
@@ -187,11 +184,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 +200,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]);
       }
     }
@@ -225,12 +218,11 @@ 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();
 
-  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 == $entity->getRevisionId()) {
           unset($field_data[$sub_table][$key]);
         }
       }
diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc
index 768ee7d..749af8a 100644
--- a/core/modules/file/file.field.inc
+++ b/core/modules/file/file.field.inc
@@ -228,11 +228,9 @@ function file_field_prepare_view($entity_type, $entities, $field, $instances, $l
  * 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_usage_add(file_load($item['fid']), 'file', $entity_type, $id);
+    file_usage_add(file_load($item['fid']), 'file', $entity_type, $entity->id());
   }
 }
 
@@ -242,13 +240,11 @@ 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_usage_add(file_load($item['fid']), 'file', $entity_type, $id);
+      file_usage_add(file_load($item['fid']), 'file', $entity_type, $entity->id());
     }
     return;
   }
@@ -267,7 +263,7 @@ function file_field_update($entity_type, $entity, $field, $instance, $langcode,
       $original_fids[] = $original_item['fid'];
       if (isset($original_item['fid']) && !in_array($original_item['fid'], $current_fids)) {
         // Decrement the file usage count by 1.
-        file_usage_delete(file_load($original_item['fid']), 'file', $entity_type, $id);
+        file_usage_delete(file_load($original_item['fid']), 'file', $entity_type, $entity->id());
       }
     }
   }
@@ -275,7 +271,7 @@ function file_field_update($entity_type, $entity, $field, $instance, $langcode,
   // Add new usage entries for newly added files.
   foreach ($items as $item) {
     if (!in_array($item['fid'], $original_fids)) {
-      file_usage_add(file_load($item['fid']), 'file', $entity_type, $id);
+      file_usage_add(file_load($item['fid']), 'file', $entity_type, $entity->id());
     }
   }
 }
@@ -284,11 +280,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_usage_delete(file_load($item['fid']), 'file', $entity_type, $id, 0);
+    file_usage_delete(file_load($item['fid']), 'file', $entity_type, $entity->id(), 0);
   }
 }
 
@@ -296,10 +290,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.
-    file_usage_delete(file_load($item['fid']), 'file', $entity_type, $id);
+    file_usage_delete(file_load($item['fid']), 'file', $entity_type, $entity->id());
   }
 }
 
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

