Commit 3a7bfeac authored by catch's avatar catch

Issue #1983554 by plach, effulgentsia, Berdir: Remove BC-mode from EntityNG .

parent 2de01f4f
......@@ -9,6 +9,7 @@
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Language\Language;
use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Uuid\Uuid;
use Drupal\field\FieldInfo;
......@@ -569,15 +570,20 @@ protected function doLoadFieldItems($entities, $age) {
}
// Load field data.
$all_langcodes = array_keys(language_list());
foreach ($fields as $field_name => $field) {
$table = $load_current ? static::_fieldTableName($field) : static::_fieldRevisionTableName($field);
// If the field is translatable ensure that only values having valid
// languages are retrieved. Since we are loading values for multiple
// entities, we cannot limit the query to the available translations.
$langcodes = $field['translatable'] ? $all_langcodes : array(Language::LANGCODE_NOT_SPECIFIED);
$results = $this->database->select($table, 't')
->fields('t')
->condition($load_current ? 'entity_id' : 'revision_id', $ids, 'IN')
->condition('langcode', field_available_languages($this->entityType, $field), 'IN')
->orderBy('delta')
->condition('deleted', 0)
->condition('langcode', $langcodes, 'IN')
->orderBy('delta')
->execute();
$delta_count = array();
......@@ -597,7 +603,7 @@ protected function doLoadFieldItems($entities, $age) {
}
// Add the item to the field values for the entity.
$entities[$row->entity_id]->{$field_name}[$row->langcode][] = $item;
$entities[$row->entity_id]->getTranslation($row->langcode)->{$field_name}[$delta_count[$row->entity_id][$row->langcode]] = $item;
$delta_count[$row->entity_id][$row->langcode]++;
}
}
......@@ -621,29 +627,19 @@ protected function doSaveFieldItems(EntityInterface $entity, $update) {
$table_name = static::_fieldTableName($field);
$revision_name = static::_fieldRevisionTableName($field);
$all_langcodes = field_available_languages($entity_type, $field);
$field_langcodes = array_intersect($all_langcodes, array_keys((array) $entity->$field_name));
// Delete and insert, rather than update, in case a value was added.
if ($update) {
// Delete language codes present in the incoming $entity->$field_name.
// Delete all language codes if $entity->$field_name is empty.
$langcodes = !empty($entity->$field_name) ? $field_langcodes : $all_langcodes;
if ($langcodes) {
// Only overwrite the field's base table if saving the default revision
// of an entity.
if ($entity->isDefaultRevision()) {
$this->database->delete($table_name)
->condition('entity_id', $id)
->condition('langcode', $langcodes, 'IN')
->execute();
}
$this->database->delete($revision_name)
// Only overwrite the field's base table if saving the default revision
// of an entity.
if ($entity->isDefaultRevision()) {
$this->database->delete($table_name)
->condition('entity_id', $id)
->condition('revision_id', $vid)
->condition('langcode', $langcodes, 'IN')
->execute();
}
$this->database->delete($revision_name)
->condition('entity_id', $id)
->condition('revision_id', $vid)
->execute();
}
// Prepare the multi-insert query.
......@@ -655,8 +651,12 @@ protected function doSaveFieldItems(EntityInterface $entity, $update) {
$query = $this->database->insert($table_name)->fields($columns);
$revision_query = $this->database->insert($revision_name)->fields($columns);
foreach ($field_langcodes as $langcode) {
$items = (array) $entity->{$field_name}[$langcode];
$langcodes = $field['translatable'] ? array_keys($entity->getTranslationLanguages()) : array(Language::LANGCODE_NOT_SPECIFIED);
foreach ($langcodes as $langcode) {
$items = $entity->getTranslation($langcode)->{$field_name}->getValue();
if (!isset($items)) {
continue;
}
$delta_count = 0;
foreach ($items as $delta => $item) {
// We now know we have someting to insert.
......
......@@ -330,9 +330,6 @@ protected function attachPropertyData(array &$entities, $revision_id = FALSE) {
public function save(EntityInterface $entity) {
$transaction = $this->database->startTransaction();
try {
// Ensure we are dealing with the actual entity.
$entity = $entity->getNGEntity();
// Sync the changes made in the fields array to the internal values array.
$entity->updateOriginalValues();
......@@ -572,11 +569,6 @@ public function delete(array $entities) {
$entity_class = $this->entityClass;
$entity_class::preDelete($this, $entities);
// Ensure we are dealing with the actual entities.
foreach ($entities as $id => $entity) {
$entities[$id] = $entity->getNGEntity();
}
foreach ($entities as $entity) {
$this->invokeHook('predelete', $entity);
}
......
......@@ -412,20 +412,6 @@ public function getExportProperties() {
return array();
}
/**
* Implements \Drupal\Core\Entity\EntityInterface::getBCEntity().
*/
public function getBCEntity() {
return $this;
}
/**
* Implements \Drupal\Core\Entity\EntityInterface::getNGEntity().
*/
public function getNGEntity() {
return $this;
}
/**
* {@inheritdoc}
*/
......
This diff is collapsed.
......@@ -274,31 +274,10 @@ public function validate(array $form, array &$form_state) {
$violations = array();
// @todo Simplify when all entity types are converted to EntityNG.
if ($entity instanceof EntityNG) {
foreach ($entity as $field_name => $field) {
$field_violations = $field->validate();
if (count($field_violations)) {
$violations[$field_name] = $field_violations;
}
}
}
else {
// For BC entities, iterate through each field instance and
// instantiate NG items objects manually.
$definitions = \Drupal::entityManager()->getFieldDefinitions($entity_type, $entity->bundle());
foreach (field_info_instances($entity_type, $entity->bundle()) as $field_name => $instance) {
$langcode = field_is_translatable($entity_type, $instance->getField()) ? $entity_langcode : Language::LANGCODE_NOT_SPECIFIED;
// Create the field object.
$items = isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : array();
// @todo Exception : calls setValue(), tries to set the 'formatted'
// property.
$field = \Drupal::typedData()->create($definitions[$field_name], $items, $field_name, $entity);
$field_violations = $field->validate();
if (count($field_violations)) {
$violations[$field->getName()] = $field_violations;
}
foreach ($entity as $field_name => $field) {
$field_violations = $field->validate();
if (count($field_violations)) {
$violations[$field_name] = $field_violations;
}
}
......
......@@ -290,26 +290,6 @@ public function isDefaultRevision($new_value = NULL);
*/
public function getExportProperties();
/**
* Gets a backward compatibility decorator entity.
*
* @return \Drupal\Core\Entity\EntityInterface
* The backward compatible entity.
*
* @see \Drupal\Core\Entity\EntityInterface::getNGEntity()
*/
public function getBCEntity();
/**
* Removes any possible (backward compatibility) decorator in use.
*
* @return \Drupal\Core\Entity\EntityInterface
* The original, not backward compatible entity object.
*
* @see \Drupal\Core\Entity\EntityInterface::getBCEntity()
*/
public function getNGEntity();
/**
* Returns the translation support status.
*
......
......@@ -67,13 +67,6 @@ class EntityNG extends Entity {
*/
protected $fields = array();
/**
* An instance of the backward compatibility decorator.
*
* @var EntityBCDecorator
*/
protected $bcEntity;
/**
* Local cache for the entity language.
*
......@@ -306,13 +299,6 @@ protected function getTranslatedField($property_name, $langcode) {
if (isset($this->values[$property_name][$langcode])) {
$value = $this->values[$property_name][$langcode];
}
// @todo Remove this once the BC decorator is gone.
elseif ($property_name != 'langcode' && $langcode == Language::LANGCODE_DEFAULT) {
$default_langcode = $this->language()->id;
if (isset($this->values[$property_name][$default_langcode])) {
$value = $this->values[$property_name][$default_langcode];
}
}
$field = \Drupal::typedData()->getPropertyInstance($this, $property_name, $value);
$field->setLangcode($langcode);
$this->fields[$property_name][$langcode] = $field;
......@@ -570,6 +556,10 @@ protected function initializeTranslation($langcode) {
* {@inheritdoc}
*/
public function hasTranslation($langcode) {
$default_language = $this->language ?: $this->getDefaultLanguage();
if ($langcode == $default_language->id) {
$langcode = Language::LANGCODE_DEFAULT;
}
return !empty($this->translations[$langcode]['status']);
}
......@@ -615,10 +605,10 @@ public function addTranslation($langcode, array $values = array()) {
*/
public function removeTranslation($langcode) {
if (isset($this->translations[$langcode]) && $langcode != Language::LANGCODE_DEFAULT && $langcode != $this->getDefaultLanguage()->id) {
foreach ($this->getPropertyDefinitions() as $definition) {
foreach ($this->getPropertyDefinitions() as $name => $definition) {
if (!empty($definition['translatable'])) {
unset($this->values[$langcode]);
unset($this->fields[$langcode]);
unset($this->values[$name][$langcode]);
unset($this->fields[$name][$langcode]);
}
}
$this->translations[$langcode]['status'] = static::TRANSLATION_REMOVED;
......@@ -663,18 +653,6 @@ public function translations() {
return $this->getTranslationLanguages(FALSE);
}
/**
* Overrides Entity::getBCEntity().
*/
public function getBCEntity() {
if (!isset($this->bcEntity)) {
// Initialize field definitions so that we can pass them by reference.
$this->getPropertyDefinitions();
$this->bcEntity = new EntityBCDecorator($this, $this->fieldDefinitions);
}
return $this->bcEntity;
}
/**
* Updates the original values with the interim changes.
*/
......@@ -695,8 +673,8 @@ public function updateOriginalValues() {
/**
* Implements the magic method for setting object properties.
*
* Uses default language always.
* For compatibility mode to work this must return a reference.
* @todo: A lot of code still uses non-fields (e.g. $entity->content in render
* controllers by reference. Clean that up.
*/
public function &__get($name) {
// If this is an entity field, handle it accordingly. We first check whether
......@@ -712,11 +690,6 @@ public function &__get($name) {
$return = $this->getTranslatedField($name, $this->activeLangcode);
return $return;
}
// Allow the EntityBCDecorator to directly access the values and fields.
// @todo: Remove once the EntityBCDecorator gets removed.
if ($name == 'values' || $name == 'fields') {
return $this->$name;
}
// Else directly read/write plain values. That way, non-field entity
// properties can always be accessed directly.
if (!isset($this->values[$name])) {
......@@ -743,6 +716,11 @@ public function __set($name, $value) {
elseif ($this->getPropertyDefinition($name)) {
$this->getTranslatedField($name, $this->activeLangcode)->setValue($value);
}
// The translations array is unset when cloning the entity object, we just
// need to restore it.
elseif ($name == 'translations') {
$this->translations = $value;
}
// Else directly read/write plain values. That way, fields not yet converted
// to the entity field API can always be directly accessed.
else {
......@@ -804,8 +782,6 @@ public function createDuplicate() {
* Magic method: Implements a deep clone.
*/
public function __clone() {
$this->bcEntity = NULL;
// Avoid deep-cloning when we are initializing a translation object, since
// it will represent the same entity, only with a different active language.
if (!$this->translationInitialize) {
......@@ -815,7 +791,15 @@ public function __clone() {
$this->fields[$name][$langcode]->setContext($name, $this);
}
}
// Ensure the translations array is actually cloned by removing the
// original reference and re-creating its values.
$this->clearTranslationCache();
$translations = $this->translations;
unset($this->translations);
// This will trigger the magic setter as the translations array is
// undefined now.
$this->translations = $translations;
}
}
......
......@@ -42,11 +42,6 @@ protected function loadFieldItems(array $entities, $age) {
$info = entity_get_info($this->entityType);
$use_cache = $load_current && $info['field_cache'];
// Ensure we are working with a BC mode entity.
foreach ($entities as $id => $entity) {
$entities[$id] = $entity->getBCEntity();
}
// Assume all entities will need to be queried. Entities found in the cache
// will be removed from the list.
$queried_entities = $entities;
......@@ -65,8 +60,13 @@ protected function loadFieldItems(array $entities, $age) {
$cid = "field:{$this->entityType}:$id";
if (isset($cache[$cid])) {
unset($queried_entities[$id]);
foreach ($cache[$cid]->data as $field_name => $values) {
$entity->$field_name = $values;
foreach ($cache[$cid]->data as $langcode => $values) {
$translation = $entity->getTranslation($langcode);
// We do not need to worry about field translatability here, the
// translation object will manage that automatically.
foreach ($values as $field_name => $items) {
$translation->$field_name = $items;
}
}
}
}
......@@ -87,8 +87,11 @@ protected function loadFieldItems(array $entities, $age) {
foreach ($queried_entities as $id => $entity) {
$data = array();
$instances = field_info_instances($this->entityType, $entity->bundle());
foreach ($instances as $instance) {
$data[$instance['field_name']] = $queried_entities[$id]->{$instance['field_name']};
foreach ($entity->getTranslationLanguages() as $langcode => $language) {
$translation = $entity->getTranslation($langcode);
foreach ($instances as $instance) {
$data[$langcode][$instance['field_name']] = $translation->{$instance['field_name']}->getValue();
}
}
$cid = "field:{$this->entityType}:$id";
cache('field')->set($cid, $data);
......@@ -110,9 +113,6 @@ protected function loadFieldItems(array $entities, $age) {
* TRUE if the entity is being updated, FALSE if it is being inserted.
*/
protected function saveFieldItems(EntityInterface $entity, $update = TRUE) {
// Ensure we are working with a BC mode entity.
$entity = $entity->getBCEntity();
$this->doSaveFieldItems($entity, $update);
if ($update) {
......@@ -134,9 +134,6 @@ protected function saveFieldItems(EntityInterface $entity, $update = TRUE) {
* The entity.
*/
protected function deleteFieldItems(EntityInterface $entity) {
// Ensure we are working with a BC mode entity.
$entity = $entity->getBCEntity();
$this->doDeleteFieldItems($entity);
$entity_info = $entity->entityInfo();
......@@ -156,7 +153,7 @@ protected function deleteFieldItems(EntityInterface $entity) {
* The entity. It must have a revision ID attribute.
*/
protected function deleteFieldItemsRevision(EntityInterface $entity) {
$this->doDeleteFieldItemsRevision($entity->getBCEntity());
$this->doDeleteFieldItemsRevision($entity);
}
/**
......
......@@ -99,10 +99,6 @@ public function setValue($value, $notify = TRUE) {
// Both the entity ID and the entity object may be passed as value. The
// reference may also be unset by passing NULL as value.
if (!isset($value) || $value instanceof EntityInterface) {
// Ensure we reference a NG Entity object.
if (isset($value)) {
$value = $value->getNGEntity();
}
$this->target = $value;
}
elseif (!is_scalar($value) || empty($this->definition['constraints']['EntityType'])) {
......
......@@ -142,8 +142,7 @@ public function addField($field, $type, $langcode) {
}
$entity = $entity_manager
->getStorageController($entity_type)
->create($values)
->getNGEntity();
->create($values);
$propertyDefinitions = $entity->$field_name->getPropertyDefinitions();
// If the column is not yet known, ie. the
......@@ -196,8 +195,7 @@ public function addField($field, $type, $langcode) {
}
$entity = $entity_manager
->getStorageController($entity_type)
->create($values)
->getNGEntity();
->create($values);
$propertyDefinitions = $entity->$specifier->getPropertyDefinitions();
$relationship_specifier = $specifiers[$key + 1];
$next_index_prefix = $relationship_specifier;
......
......@@ -610,19 +610,9 @@ function content_translation_form_alter(array &$form, array &$form_state) {
// Handle fields shared between translations when there is at least one
// translation available or a new one is being created.
if (!$entity->isNew() && (!isset($translations[$form_langcode]) || count($translations) > 1)) {
$entity = $entity->getNGEntity();
if ($entity instanceof EntityNG) {
foreach ($entity->getPropertyDefinitions() as $property_name => $definition) {
if (isset($form[$property_name])) {
$form[$property_name]['#multilingual'] = !empty($definition['translatable']);
}
}
}
else {
foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) {
$field_name = $instance['field_name'];
$field = $instance->getField();
$form[$field_name]['#multilingual'] = !empty($field['translatable']);
foreach ($entity->getPropertyDefinitions() as $property_name => $definition) {
if (isset($form[$property_name])) {
$form[$property_name]['#multilingual'] = !empty($definition['translatable']);
}
}
}
......@@ -647,18 +637,7 @@ function content_translation_field_language_alter(&$display_language, $context)
foreach ($entity->translation as $langcode => $translation) {
if ($langcode == $context['langcode'] || !content_translation_view_access($entity, $langcode)) {
// Unset unaccessible field translations: if the field is untranslatable
// unsetting a language different from Language::LANGCODE_NOT_SPECIFIED has no
// effect.
foreach ($instances as $instance) {
// @todo BC entities have the same value accessibile both with the
// entity language and with Language::LANGCODE_DEFAULT. We need need to unset
// both until we remove the BC layer.
if ($langcode == $entity_langcode) {
unset($entity->{$instance['field_name']}[Language::LANGCODE_DEFAULT]);
}
unset($entity->{$instance['field_name']}[$langcode]);
}
$entity->removeTranslation($langcode);
}
}
......
......@@ -236,23 +236,8 @@ function content_translation_edit_page(EntityInterface $entity, Language $langua
* The language to be used as target.
*/
function content_translation_prepare_translation(EntityInterface $entity, Language $source, Language $target) {
// @todo Unify field and property handling.
$entity = $entity->getNGEntity();
if ($entity instanceof EntityNG) {
$source_translation = $entity->getTranslation($source->id);
$entity->addTranslation($target->id, $source_translation->getPropertyValues());
}
else {
$instances = field_info_instances($entity->entityType(), $entity->bundle());
foreach ($instances as $field_name => $instance) {
$field = $instance->getField();
if (!empty($field['translatable'])) {
$value = $entity->get($field_name);
$value[$target->id] = isset($value[$source->id]) ? $value[$source->id] : array();
$entity->set($field_name, $value);
}
}
}
$source_translation = $entity->getTranslation($source->id);
$entity->addTranslation($target->id, $source_translation->getPropertyValues());
}
/**
......
......@@ -37,12 +37,6 @@ public function __construct(EntityManager $entityManager) {
* {@inheritdoc}
*/
public function synchronizeFields(EntityInterface $entity, $sync_langcode, $original_langcode = NULL) {
// Field synchronization is only supported for NG entities.
$entity = $entity->getNGEntity();
if (!($entity instanceof EntityNG)) {
return;
}
$translations = $entity->getTranslationLanguages();
// If we have no information about what to sync to, if we are creating a new
......
......@@ -54,23 +54,24 @@ protected function getNewEntityValues($langcode) {
}
/**
* Overrides ContentTranslationTest::testTranslationUI().
* Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::::testTranslationUI().
*
* @todo This override is a copy-paste of parts of the parent method. Turn
* ConfigTest into a properly translatable entity and remove this override.
* @todo Config entities are not translatable, but Content Translation module
* doesn't have a clean way to enforce that, so this test is here to ensure
* the module doesn't interfere with basic config entity storage.
* Reconsider the purpose of this test after http://drupal.org/node/2004244
* and either remove it or rewrite it to more clearly test what is needed.
*/
function testTranslationUI() {
// Create a new test entity with original values in the default language.
$default_langcode = $this->langcodes[0];
$values[$default_langcode] = $this->getNewEntityValues($default_langcode);
$id = $this->createEntity($values[$default_langcode], $default_langcode);
$values = $this->getNewEntityValues($default_langcode);
$id = $this->createEntity($values, $default_langcode);
$entity = entity_load($this->entityType, $id, TRUE);
$this->assertTrue($entity, 'Entity found in the database.');
$translation = $this->getTranslation($entity, $default_langcode);
foreach ($values[$default_langcode] as $property => $value) {
$stored_value = $this->getValue($translation, $property, $default_langcode);
$value = is_array($value) ? $value[0]['value'] : $value;
foreach ($values as $property => $value) {
$stored_value = $entity->{$property};
$message = format_string('@property correctly stored in the default language.', array('@property' => $property));
$this->assertIdentical($stored_value, $value, $message);
}
......
......@@ -258,9 +258,7 @@ protected function getFormSubmitAction(EntityInterface $entity) {
* The translation object to act on.
*/
protected function getTranslation(EntityInterface $entity, $langcode) {
// @todo remove once EntityBCDecorator is gone.
$entity = $entity->getNGEntity();
return $entity instanceof EntityNG ? $entity->getTranslation($langcode) : $entity;
return $entity->getTranslation($langcode);
}
/**
......@@ -278,13 +276,7 @@ protected function getTranslation(EntityInterface $entity, $langcode) {
*/
protected function getValue(EntityInterface $translation, $property, $langcode) {
$key = $property == 'user_id' ? 'target_id' : 'value';
// @todo remove EntityBCDecorator condition once EntityBCDecorator is gone.
if (($translation instanceof EntityInterface) && !($translation instanceof EntityNG) && !($translation instanceof EntityBCDecorator)) {
return is_array($translation->$property) ? $translation->{$property}[$langcode][0][$key] : $translation->$property;
}
else {
return $translation->get($property)->{$key};
}
return $translation->get($property)->{$key};
}
}
......@@ -353,13 +353,11 @@ function _field_invoke_widget_target($form_display) {
* values.
*/
function field_attach_preprocess(EntityInterface $entity, $element, &$variables) {
// Ensure we are working with a BC mode entity.
$entity = $entity->getBCEntity();
foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) {
$field_name = $instance['field_name'];
if (isset($element[$field_name]['#language'])) {
$langcode = $element[$field_name]['#language'];
$variables[$field_name] = isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : NULL;
$variables[$field_name] = $entity->getTranslation($langcode)->{$field_name}->getValue();
}
}
......
......@@ -558,9 +558,6 @@ function field_read_instances($conditions = array(), $include_additional = array
* @see field_form_set_state()
*/
function field_attach_form(EntityInterface $entity, &$form, &$form_state, $langcode = NULL, array $options = array()) {
// Ensure we are working with a BC mode entity.
$entity = $entity->getBCEntity();
// Set #parents to 'top-level' by default.
$form += array('#parents' => array());
......@@ -615,11 +612,6 @@ function field_attach_form(EntityInterface $entity, &$form, &$form_state, $langc
* @deprecated as of Drupal 8.0. Use the entity system instead.
*/
function field_attach_form_validate(EntityInterface $entity, $form, &$form_state, array $options = array()) {
// Only support NG entities.
if (!($entity->getNGEntity() instanceof EntityNG)) {
return;
}
$has_violations = FALSE;
foreach ($entity as $field_name => $field) {
$definition = $field->getDefinition();
......@@ -663,9 +655,6 @@ function field_attach_form_validate(EntityInterface $entity, $form, &$form_state
* @deprecated as of Drupal 8.0. Use the entity system instead.
*/
function field_attach_extract_form_values(EntityInterface $entity, $form, &$form_state, array $options = array()) {
// Ensure we are working with a BC mode entity.
$entity = $entity->getBCEntity();
// Extract field values from submitted values.
$form_display = $form_state['form_display'];
field_invoke_method('extractFormValues', _field_invoke_widget_target($form_display), $entity, $form, $form_state, $options);
......@@ -714,9 +703,6 @@ function field_attach_prepare_view($entity_type, array $entities, array $display
$prepare = array();
foreach ($entities as $id => $entity) {
if (empty($entity->_field_view_prepared)) {
// Ensure we are working with a BC mode entity.
$entity = $entity->getBCEntity();
// Add this entity to the items to be prepared.
$prepare[$id] = $entity;
......@@ -770,8 +756,6 @@ function field_attach_prepare_view($entity_type, array $entities, array $display
* @deprecated as of Drupal 8.0. Use the entity system instead.
*/
function field_attach_view(EntityInterface $entity, EntityDisplay $display, $langcode = NULL, array $options = array()) {
// Ensure we are working with a BC mode entity.
$entity = $entity->getBCEntity();
// Determine the actual language code to display for each field, given the
// language codes available in the field data.
$options['langcode'] = field_language($entity, NULL, $langcode);
......@@ -783,8 +767,6 @@ function field_attach_view(EntityInterface $entity, EntityDisplay $display, $lan
};
$null = NULL;
$output = field_invoke_method('view', $target_function, $entity, $null, $null, $options);
// Remove the BC layer now.
$entity = $entity->getNGEntity();
// Let other modules alter the renderable array.
$view_mode = $display->originalMode;
......@@ -822,7 +804,6 @@ function field_attach_view(EntityInterface $entity, EntityDisplay $display, $lan
* $entity->getTranslation($langcode)->{$field_name}
*/
function field_get_items(EntityInterface $entity, $field_name, $langcode = NULL) {
$entity = $entity->getBCEntity();
$langcode = field_language($entity, $field_name, $langcode);
return isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : array();
}
......
......@@ -577,8 +577,7 @@ function _field_filter_xss_display_allowed_tags() {
* @param $field_name
* The name of the field to display.
* @param $item
* The field value to display, as found in
* $entity->field_name[$langcode][$delta].
* The field item value to display.
* @param $display
* Can be either the name of a view mode, or an array of display settings. See
* field_view_field() for more information.
......@@ -592,9 +591,6 @@ function _field_filter_xss_display_allowed_tags() {
function field_view_value(EntityInterface $entity, $field_name, $item, $display = array(), $langcode = NULL) {
$output = array();
// Ensure we are working with a BC mode entity.
$entity = $entity->getBCEntity();
if ($field = field_info_field($entity->entityType(), $field_name)) {
// Determine the langcode that will be used by language fallback.
$langcode = field_language($entity, $field_name, $langcode);
......@@ -602,7 +598,7 @@ function field_view_value(EntityInterface $entity, $field_name, $item, $display
// Push the item as the single value for the field, and defer to
// field_view_field() to build the render array for the whole field.
$clone = clone $entity;
$clone->{$field_name}[$langcode] = array($item);
$clone->getTranslation($langcode)->{$field_name}->setValue(array($item));
$elements = field_view_field($clone, $field_name, $display, $langcode);
// Extract the part of the render array we need.
......@@ -700,7 +696,7 @@ function field_view_field(EntityInterface $entity, $field_name, $display_options
$display_langcode = field_language($entity, $field_name, $langcode);