diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index e2d5d22..8985f31 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -416,7 +416,7 @@ public function getFieldDefinitions() { /** * {@inheritdoc} */ - public function getFieldValues() { + public function toArray() { $values = array(); foreach ($this->getFields() as $name => $property) { $values[$name] = $property->getValue(); @@ -424,14 +424,6 @@ public function getFieldValues() { return $values; } - public function setFieldValues(array $values) { - $values = array(); - foreach ($values as $name => $field_values) { - $this->set($name, $field_values); - } - return $this; - } - /** * {@inheritdoc} */ diff --git a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php index b952cfe..079e5f6 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php @@ -177,17 +177,7 @@ public function getFields($include_computed = FALSE); * @return array * An array keyed by property name containing the property value. */ - public function getFieldValues(); - - /** - * Sets field values. - * - * @param array $values - * Array of values to set, keyed by field name. - * - * @return $this - */ - public function setFieldValues(array $values); + public function toArray(); /** * React to changes to a child field. diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityTypedDataWrapper.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityTypedDataWrapper.php index 3663b48..3cc85fd 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityTypedDataWrapper.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityTypedDataWrapper.php @@ -7,7 +7,9 @@ namespace Drupal\Core\Entity\Plugin\DataType; use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\TypedData\ComplexDataInterface; +use Drupal\Core\TypedData\DataDefinitionInterface; use Drupal\Core\TypedData\TypedDataInterface; /** @@ -32,6 +34,9 @@ class EntityTypedDataWrapper implements \IteratorAggregate, ComplexDataInterface protected $entity; public function __construct(ContentEntityInterface $entity) { + if ($entity instanceof DataDefinitionInterface) { + debug(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)); + } $this->entity = $entity; } @@ -64,7 +69,7 @@ public function getProperties($include_computed = FALSE) { * {@inheritdoc} */ public function getPropertyValues() { - return $this->entity->getFieldValues(); + return $this->entity->toArray(); } /** diff --git a/core/modules/content_translation/content_translation.pages.inc b/core/modules/content_translation/content_translation.pages.inc index 27abe9f..44c82d0 100644 --- a/core/modules/content_translation/content_translation.pages.inc +++ b/core/modules/content_translation/content_translation.pages.inc @@ -229,6 +229,6 @@ function content_translation_edit_page(EntityInterface $entity, Language $langua function content_translation_prepare_translation(EntityInterface $entity, Language $source, Language $target) { if ($entity instanceof ContentEntityInterface) { $source_translation = $entity->getTranslation($source->id); - $entity->addTranslation($target->id, $source_translation->getFieldValues()); + $entity->addTranslation($target->id, $source_translation->toArray()); } } diff --git a/core/modules/hal/lib/Drupal/hal/Normalizer/EntityReferenceItemNormalizer.php b/core/modules/hal/lib/Drupal/hal/Normalizer/EntityReferenceItemNormalizer.php index 64174d9..06e0ad8 100644 --- a/core/modules/hal/lib/Drupal/hal/Normalizer/EntityReferenceItemNormalizer.php +++ b/core/modules/hal/lib/Drupal/hal/Normalizer/EntityReferenceItemNormalizer.php @@ -68,7 +68,7 @@ public function normalize($field_item, $format = NULL, array $context = array()) // Normalize the target entity. $embedded = $this->serializer->normalize($target_entity, $format, $context); // @todo Config entities currently can not be serialized, skip them. - if (!$embedded) { + if (empty($embedded['_links']['self'])) { return array(); } $link = $embedded['_links']['self']; diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php index acf653b..dc444aa 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php @@ -282,7 +282,7 @@ protected function assertReadWrite($entity_type) { $entity->name[0]->setPropertyValues(array('value' => 'bar')); $this->assertEqual($entity->name->value, 'bar', format_string('%entity_type: Field value has been set via setPropertyValue()', array('%entity_type' => $entity_type))); - $values = $entity->getFieldValues(); + $values = $entity->toArray(); $this->assertEqual($values['name'], array(0 => array('value' => 'bar')), format_string('%entity_type: Field value has been retrieved via getPropertyValue() from an entity.', array('%entity_type' => $entity_type))); //$entity->setPropertyValues(array('name' => 'foo')); //$this->assertEqual($entity->name->value, 'foo', format_string('%entity_type: Field value has been set via setPropertyValue() on an entity.', array('%entity_type' => $entity_type))); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php index c5f2ae7..7dcbd6b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php @@ -205,7 +205,10 @@ protected function _testMultilingualProperties($entity_type) { 'user_id' => array(0 => $uid), ); } - $entity->getTranslation($langcode)->setFieldValues($properties[$langcode]); + $translation = $entity->getTranslation($langcode); + foreach ($properties[$langcode] as $field_name => $values) { + $translation->set($field_name, $values); + } } $entity->save(); diff --git a/core/modules/system/tests/modules/condition_test/lib/Drupal/condition_test/FormController.php b/core/modules/system/tests/modules/condition_test/lib/Drupal/condition_test/FormController.php index 57c3009..92b4319 100644 --- a/core/modules/system/tests/modules/condition_test/lib/Drupal/condition_test/FormController.php +++ b/core/modules/system/tests/modules/condition_test/lib/Drupal/condition_test/FormController.php @@ -7,6 +7,7 @@ namespace Drupal\condition_test; +use Drupal\Core\Entity\Plugin\DataType\EntityTypedDataWrapper; use Drupal\Core\Form\FormInterface; use Drupal\Core\Condition\ConditionManager; @@ -65,7 +66,7 @@ public function submitForm(array &$form, array &$form_state) { $bundles = implode(' and ', $config['bundles']); drupal_set_message(t('The bundles are @bundles', array('@bundles' => $bundles))); $article = node_load(1); - $this->condition->setContextValue('node', $article); + $this->condition->setContextValue('node', new EntityTypedDataWrapper($article)); if ($this->condition->execute()) { drupal_set_message(t('Executed successfully.')); }