diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php b/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php index 1048ca1..d436e49 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php @@ -156,19 +156,12 @@ protected function attachLoad(&$queried_entities, $load_revision = FALSE) { // Map the loaded stdclass records into entity objects and according fields. $queried_entities = $this->mapFromStorageRecords($queried_entities, $load_revision); - // Activate backward-compatibility mode to attach fields. if ($this->entityInfo['fieldable']) { - // Prepare BC compatible entities before passing them to the field API. - $bc_entities = array(); - foreach ($queried_entities as $key => $entity) { - $bc_entities[$key] = $entity->getBCEntity(); - } - if ($load_revision) { - field_attach_load_revision($this->entityType, $bc_entities); + field_attach_load_revision($this->entityType, $queried_entities); } else { - field_attach_load($this->entityType, $bc_entities); + field_attach_load($this->entityType, $queried_entities); } } @@ -419,7 +412,7 @@ protected function invokeHook($hook, EntityInterface $entity) { $function = 'field_attach_delete_revision'; } if (!empty($this->entityInfo['fieldable']) && function_exists($function)) { - $function($entity->getBCEntity()); + $function($entity); } // Invoke the hook. diff --git a/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php b/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php index ef9bc89..bfb41a8 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php +++ b/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php @@ -27,7 +27,7 @@ public function form(array $form, array &$form_state, EntityInterface $entity) { // entity fields. $info = $entity->entityInfo(); if (!empty($info['fieldable'])) { - field_attach_form($entity->getBCEntity(), $form, $form_state, $this->getFormLangcode($form_state)); + field_attach_form($entity, $form, $form_state, $this->getFormLangcode($form_state)); } return $form; } @@ -42,7 +42,7 @@ public function validate(array $form, array &$form_state) { $info = $entity->entityInfo(); if (!empty($info['fieldable'])) { - field_attach_form_validate($entity->getBCEntity(), $form, $form_state); + field_attach_form_validate($entity, $form, $form_state); } // @todo Remove this. @@ -92,7 +92,7 @@ public function buildEntity(array $form, array &$form_state) { // Invoke field API for copying field values. if ($info['fieldable']) { - field_attach_extract_form_values($entity->getBCEntity(), $form, $form_state); + field_attach_extract_form_values($entity, $form, $form_state); } return $entity; } diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc index de035d2..029bd4a 100644 --- a/core/modules/field/field.attach.inc +++ b/core/modules/field/field.attach.inc @@ -821,6 +821,9 @@ function _field_invoke_widget_target() { * @see field_form_set_state() */ function field_attach_form(EntityInterface $entity, &$form, &$form_state, $langcode = NULL, array $options = array()) { + // Enable BC if necessary. + $entity = $entity->getBCEntity(); + // Set #parents to 'top-level' by default. $form += array('#parents' => array()); @@ -894,7 +897,11 @@ function field_attach_load($entity_type, $entities, $age = FIELD_LOAD_CURRENT, $ // Assume all entities will need to be queried. Entities found in the cache // will be removed from the list. - $queried_entities = $entities; + $queried_entities = array(); + foreach ($entities as $entity) { + // Enable BC if necessary. + $queried_entities[$entity->id()] = $entity->getBEntity(); + } // Fetch available entities from cache, if applicable. if ($cache_read) { @@ -1028,6 +1035,9 @@ function field_attach_load_revision($entity_type, $entities, $options = array()) * details. */ function field_attach_validate(EntityInterface $entity, array $options = array()) { + // Enable BC if necessary. + $entity = $entity->getBCEntity(); + $errors = array(); // Check generic, field-type-agnostic errors first. $null = NULL; @@ -1077,6 +1087,9 @@ function field_attach_validate(EntityInterface $entity, array $options = array() * details. */ function field_attach_form_validate(EntityInterface $entity, $form, &$form_state, array $options = array()) { + // Enable BC if necessary. + $entity = $entity->getBCEntity(); + // Perform field_level validation. try { field_attach_validate($entity, $options); @@ -1114,6 +1127,9 @@ function field_attach_form_validate(EntityInterface $entity, $form, &$form_state * details. */ function field_attach_extract_form_values(EntityInterface $entity, $form, &$form_state, array $options = array()) { + // Enable BC if necessary. + $entity = $entity->getBCEntity(); + // Extract field values from submitted values. field_invoke_method('extractFormValues', _field_invoke_widget_target(), $entity, $form, $form_state, $options); @@ -1135,6 +1151,9 @@ function field_attach_extract_form_values(EntityInterface $entity, $form, &$form * The entity with fields to process. */ function field_attach_presave($entity) { + // Enable BC if necessary. + $entity = $entity->getBCEntity(); + _field_invoke('presave', $entity); // Let other modules act on presaving the entity. @@ -1156,6 +1175,9 @@ function field_attach_presave($entity) { * it leaves unspecified. */ function field_attach_insert(EntityInterface $entity) { + // Enable BC if necessary. + $entity = $entity->getBCEntity(); + _field_invoke('insert', $entity); // Let any module insert field data before the storage engine, accumulating @@ -1197,6 +1219,9 @@ function field_attach_insert(EntityInterface $entity) { * The entity with fields to save. */ function field_attach_update(EntityInterface $entity) { + // Enable BC if necessary. + $entity = $entity->getBCEntity(); + _field_invoke('update', $entity); // Let any module update field data before the storage engine, accumulating @@ -1248,6 +1273,9 @@ function field_attach_update(EntityInterface $entity) { * The entity whose field data to delete. */ function field_attach_delete(EntityInterface $entity) { + // Enable BC if necessary. + $entity = $entity->getBCEntity(); + _field_invoke('delete', $entity); // Collect the storage backends used by the fields in the entities. @@ -1281,6 +1309,9 @@ function field_attach_delete(EntityInterface $entity) { * The entity with fields to save. */ function field_attach_delete_revision(EntityInterface $entity) { + // Enable BC if necessary. + $entity = $entity->getBCEntity(); + _field_invoke('delete_revision', $entity); // Collect the storage backends used by the fields in the entities. @@ -1505,6 +1536,9 @@ function field_attach_preprocess(EntityInterface $entity, $element, &$variables) * The source language from which translate. */ function field_attach_prepare_translation(EntityInterface $entity, $langcode, EntityInterface $source_entity, $source_langcode) { + // Enable BC if necessary. + $entity = $entity->getBCEntity(); + $options = array('langcode' => $langcode); // Copy source field values into the entity to be prepared. _field_invoke_default('prepare_translation', $entity, $source_entity, $source_langcode, $options);