Commit 28152037 authored by alexpott's avatar alexpott
Browse files

Issue #2223361 by Berdir, fago, tim.plunkett: Rename...

Issue #2223361 by Berdir, fago, tim.plunkett: Rename ComplexDataInterface::getPropertyValues() to toArray(), remove setPropertyValues().
parent 2f139937
......@@ -114,16 +114,6 @@ public function get($property_name);
*/
public function set($property_name, $value);
/**
* Retrieves the exportable properties of the entity.
*
* These are the values that get saved into config.
*
* @return array
* An array of exportable properties and their values.
*/
public function toArray();
/**
* Calculates dependencies and stores them in the dependency property.
*
......
......@@ -91,22 +91,12 @@ public function getProperties($include_computed = FALSE) {
}
/**
* Implements Drupal\Core\TypedData\ComplexDataInterface::getPropertyValues().
* {@inheritdoc}
*/
public function getPropertyValues() {
public function toArray() {
return $this->getValue();
}
/**
* Implements Drupal\Core\TypedData\ComplexDataInterface::setPropertyValues().
*/
public function setPropertyValues($values) {
foreach ($values as $name => $value) {
$this->value[$name] = $value;
}
return $this;
}
/**
* Gets the definition of a contained property.
*
......
......@@ -229,7 +229,7 @@ public function getDataDefinition() {
public function getValue() {
// @todo: This does not make much sense, so remove once TypedDataInterface
// is removed. See https://drupal.org/node/2002138.
return $this->getPropertyValues();
return $this->toArray();
}
/**
......@@ -238,7 +238,9 @@ public function getValue() {
public function setValue($value, $notify = TRUE) {
// @todo: This does not make much sense, so remove once TypedDataInterface
// is removed. See https://drupal.org/node/2002138.
$this->setPropertyValues($value);
foreach ($value as $field_name => $field_value) {
$this->set($field_name, $field_value, $notify);
}
}
/**
......@@ -477,7 +479,7 @@ public function getFieldDefinitions() {
/**
* {@inheritdoc}
*/
public function getPropertyValues() {
public function toArray() {
$values = array();
foreach ($this->getProperties() as $name => $property) {
$values[$name] = $property->getValue();
......@@ -485,15 +487,6 @@ public function getPropertyValues() {
return $values;
}
/**
* {@inheritdoc}
*/
public function setPropertyValues($values) {
foreach ($values as $name => $value) {
$this->get($name)->setValue($value);
}
}
/**
* {@inheritdoc}
*/
......
......@@ -124,4 +124,15 @@ public function getFieldDefinition($name);
*/
public function getFieldDefinitions();
/**
* Returns an array of all field values.
*
* Gets an array of plain field values, including only non-computed values.
* Note that the structure varies by entity type and bundle.
*
* @return array
* An array of field values, keyed by field name.
*/
public function toArray();
}
......@@ -448,4 +448,11 @@ public function setOriginalId($id) {
return $this;
}
/**
* {@inheritdoc}
*/
public function toArray() {
return array();
}
}
......@@ -319,4 +319,12 @@ public function getOriginalId();
*/
public function setOriginalId($id);
/**
* Returns an array of all property values.
*
* @return array
* An array of property values, keyed by property name.
*/
public function toArray();
}
......@@ -70,28 +70,15 @@ public function set($property_name, $value, $notify = TRUE);
public function getProperties($include_computed = FALSE);
/**
* Gets an array of property values.
* Returns an array of all property values.
*
* Gets an array of plain property values including all not-computed
* properties.
*
* @return array
* An array keyed by property name containing the property value.
* An array of property values, keyed by property name.
*/
public function getPropertyValues();
/**
* Sets multiple property values.
*
* @param array
* The array of property values to set, keyed by property name.
*
* @throws \InvalidArgumentException
* If the value of a not existing property is to be set.
* @throws \Drupal\Core\TypedData\ReadOnlyException
* If a read-only property is set.
*/
public function setPropertyValues($values);
public function toArray();
/**
* Determines whether the data structure is empty.
......
......@@ -162,9 +162,9 @@ public function getProperties($include_computed = FALSE) {
}
/**
* Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyValues().
* {@inheritdoc}
*/
public function getPropertyValues() {
public function toArray() {
$values = array();
foreach ($this->getProperties() as $name => $property) {
$values[$name] = $property->getValue();
......@@ -172,15 +172,6 @@ public function getPropertyValues() {
return $values;
}
/**
* Implements \Drupal\Core\TypedData\ComplexDataInterface::setPropertyValues().
*/
public function setPropertyValues($values) {
foreach ($values as $name => $value) {
$this->get($name)->setValue($value);
}
}
/**
* Implements \IteratorAggregate::getIterator().
*/
......
......@@ -220,7 +220,7 @@ function testSchemaData() {
// And test some ComplexDataInterface methods.
$properties = $list->getProperties();
$this->assertTrue(count($properties) == 3 && $properties['front'] == $list['front'], 'Got the right properties for site page.');
$values = $list->getPropertyValues();
$values = $list->toArray();
$this->assertTrue(count($values) == 3 && $values['front'] == 'user', 'Got the right property values for site page.');
// Now let's try something more complex, with nested objects.
......
......@@ -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->getPropertyValues());
$entity->addTranslation($target->id, $source_translation->toArray());
}
}
......@@ -25,7 +25,7 @@ class FieldItemNormalizer extends NormalizerBase {
* Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize()
*/
public function normalize($field_item, $format = NULL, array $context = array()) {
$values = $field_item->getPropertyValues();
$values = $field_item->toArray();
if (isset($context['langcode'])) {
$values['lang'] = $context['langcode'];
}
......
......@@ -67,7 +67,7 @@ public function testNode() {
));
$node->save();
$original_values = $node->getPropertyValues();
$original_values = $node->toArray();
unset($original_values['nid']);
unset($original_values['vid']);
......@@ -102,7 +102,7 @@ public function testTerm() {
));
$term->save();
$original_values = $term->getPropertyValues();
$original_values = $term->toArray();
unset($original_values['tid']);
$normalized = $this->serializer->normalize($term, $this->format);
......
......@@ -276,14 +276,10 @@ protected function assertReadWrite($entity_type) {
// Test get and set field values.
$entity->name = 'foo';
$this->assertEqual($entity->name[0]->getPropertyValues(), array('value' => 'foo'), format_string('%entity_type: Field value has been retrieved via getPropertyValue()', array('%entity_type' => $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->getPropertyValues();
$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)));
$this->assertEqual($entity->name[0]->toArray(), array('value' => 'foo'), format_string('%entity_type: Field value has been retrieved via toArray()', array('%entity_type' => $entity_type)));
$values = $entity->toArray();
$this->assertEqual($values['name'], array(0 => array('value' => 'foo')), format_string('%entity_type: Field value has been retrieved via toArray() from an entity.', array('%entity_type' => $entity_type)));
// Make sure the user id can be set to zero.
$user_item[0]['target_id'] = 0;
......
......@@ -205,7 +205,10 @@ protected function _testMultilingualProperties($entity_type) {
'user_id' => array(0 => $uid),
);
}
$entity->getTranslation($langcode)->setPropertyValues($properties[$langcode]);
$translation = $entity->getTranslation($langcode);
foreach ($properties[$langcode] as $field_name => $values) {
$translation->set($field_name, $values);
}
}
$entity->save();
......
......@@ -434,7 +434,7 @@ public function testTypedDataMaps() {
// Test getting and setting properties.
$this->assertEqual($typed_data->get('one')->getValue(), 'eins');
$this->assertEqual($typed_data->getPropertyValues(), $value);
$this->assertEqual($typed_data->toArray(), $value);
$typed_data->set('one', 'uno');
$this->assertEqual($typed_data->get('one')->getValue(), 'uno');
// Make sure the update is reflected in the value of the map also.
......@@ -449,11 +449,6 @@ public function testTypedDataMaps() {
$this->assertEqual(array_keys($properties), array_keys($value));
$this->assertIdentical($properties['one'], $typed_data->get('one'), 'Properties are identical.');
$typed_data->setPropertyValues(array('one' => 'eins'));
$this->assertEqual($typed_data->get('one')->getValue(), 'eins');
$this->assertEqual($typed_data->get('two')->getValue(), 'zwei');
$this->assertEqual($typed_data->get('three')->getValue(), 'drei');
// Test setting a not defined property. It shouldn't show up in the
// properties, but be kept in the values.
$typed_data->setValue(array('foo' => 'bar'));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment