diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index c403b21..93de8be 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -223,7 +223,7 @@ public function getDataDefinition() { */ public function validate() { // @todo: Add the typed data manager as proper dependency. - return \Drupal::typedDataManager()->getValidator()->validate($this); + return \Drupal::typedDataManager()->getValidator()->validate(new EntityTypedDataWrapper($this)); } /** @@ -427,6 +427,17 @@ public function getFieldValues() { /** * {@inheritdoc} */ + public function setFieldValues(array $values) { + $values = array(); + foreach ($values as $name => $field_values) { + $this->set($name, $field_values); + } + return $this; + } + + /** + * {@inheritdoc} + */ public function access($operation = 'view', AccountInterface $account = NULL) { if ($operation == 'create') { return \Drupal::entityManager() @@ -504,8 +515,6 @@ public function onChange($name) { /** * {@inheritdoc} - * - * @return \Drupal\Core\Entity\ContentEntityInterface */ public function getTranslation($langcode) { // Ensure we always use the default language code when dealing with the @@ -827,7 +836,7 @@ public function __clone() { } foreach ($values as $langcode => $items) { $this->fields[$name][$langcode] = clone $items; - $this->fields[$name][$langcode]->setContext($name, $this); + $this->fields[$name][$langcode]->setContext($name, new EntityTypedDataWrapper($this)); } } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php index 90f5f90..b952cfe 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php @@ -180,6 +180,16 @@ public function getFields($include_computed = FALSE); 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); + + /** * React to changes to a child field. * * Note that this is invoked after any changes have been applied. diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityTypedDataWrapper.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityTypedDataWrapper.php index 6eed479..3663b48 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityTypedDataWrapper.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityTypedDataWrapper.php @@ -120,7 +120,7 @@ public function getString() { * {@inheritdoc} */ public function getConstraints() { - // TODO: Implement getConstraints() method. + return array(); } /** diff --git a/core/modules/comment/lib/Drupal/comment/CommentFieldNameValue.php b/core/modules/comment/lib/Drupal/comment/CommentFieldNameValue.php index 2c94151..23c4d99 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFieldNameValue.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFieldNameValue.php @@ -43,8 +43,7 @@ public function setValue($value, $notify = TRUE) { if (isset($value)) { $this->field_name = $value; // Also set the field id. - $field = $this->parent->getParent(); - $entity = $field->getParent(); + $entity = $this->parent->getEntity(); $entity->field_id = $entity->getCommentedEntityTypeId() . '__' . $value; } } 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 d3b5842..c5f2ae7 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,7 @@ protected function _testMultilingualProperties($entity_type) { 'user_id' => array(0 => $uid), ); } - $entity->getTranslation($langcode)->setPropertyValues($properties[$langcode]); + $entity->getTranslation($langcode)->setFieldValues($properties[$langcode]); } $entity->save(); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php index ec7134c..91722a7 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php @@ -86,7 +86,7 @@ protected function assertCRUD($entity_type) { // Creating a duplicate needs to result in a new UUID. $entity_duplicate = $entity->createDuplicate(); - foreach ($entity->getProperties() as $property => $value) { + foreach ($entity->getFields() as $property => $value) { switch($property) { case 'uuid': $this->assertNotNull($entity_duplicate->uuid()); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityValidationTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityValidationTest.php index 118abe9..6037c86 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityValidationTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityValidationTest.php @@ -130,7 +130,7 @@ protected function checkValidation($entity_type) { // Make sure the information provided by a violation is correct. $violation = $violations[0]; - $this->assertEqual($violation->getRoot(), $test_entity, 'Violation root is entity.'); + $this->assertEqual($violation->getRoot()->getEntity(), $test_entity, 'Violation root is entity.'); $this->assertEqual($violation->getPropertyPath(), 'name.0.value', 'Violation property path is correct.'); $this->assertEqual($violation->getInvalidValue(), $test_entity->name->value, 'Violation contains invalid value.'); @@ -148,7 +148,7 @@ protected function checkValidation($entity_type) { // Make sure the information provided by a violation is correct. $violation = $violations[0]; - $this->assertEqual($violation->getRoot(), $test_entity, 'Violation root is entity.'); + $this->assertEqual($violation->getRoot()->getEntity(), $test_entity, 'Violation root is entity.'); $this->assertEqual($violation->getPropertyPath(), 'field_test_text.0.format', 'Violation property path is correct.'); $this->assertEqual($violation->getInvalidValue(), $test_entity->field_test_text->format, 'Violation contains invalid value.'); }