diff --git a/core/lib/Drupal/Core/Config/Schema/Sequence.php b/core/lib/Drupal/Core/Config/Schema/Sequence.php index 4552feb..e66e027 100644 --- a/core/lib/Drupal/Core/Config/Schema/Sequence.php +++ b/core/lib/Drupal/Core/Config/Schema/Sequence.php @@ -92,7 +92,7 @@ public function set($index, $value) { /** * {@inheritdoc} */ - public function drop($index) { + public function removeItem($index) { $this->offsetUnset($index); return $this; } @@ -109,15 +109,6 @@ public function appendItem($value = NULL) { /** * {@inheritdoc} */ - public function clearItems() { - foreach (array_keys($this->getElements()) as $offset) { - $this->offsetUnset($offset); - } - } - - /** - * {@inheritdoc} - */ public function filter($callback) { $this->value = array_filter($this->value, $callback); unset($this->elements); diff --git a/core/lib/Drupal/Core/TypedData/ListInterface.php b/core/lib/Drupal/Core/TypedData/ListInterface.php index 33d35ae..5c6cf99 100644 --- a/core/lib/Drupal/Core/TypedData/ListInterface.php +++ b/core/lib/Drupal/Core/TypedData/ListInterface.php @@ -69,16 +69,6 @@ public function get($index); public function set($index, $value); /** - * Removes the item at the specified position. - * - * @param int $index - * Index of the item to remove. - * - * @return $this - */ - public function drop($index); - - /** * Returns the first item in this list. * * @return \Drupal\Core\TypedData\TypedDataInterface @@ -101,11 +91,14 @@ public function first(); public function appendItem($value = NULL); /** - * Removes all items from the list. + * Removes the item at the specified position. * - * @return static + * @param int $index + * Index of the item to remove. + * + * @return $this */ - public function clearItems(); + public function removeItem($index); /** * Filters the items in the list using a custom callback. diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php index 24a2443..2c7e3ed 100644 --- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php @@ -141,7 +141,7 @@ public function set($index, $value) { /** * {@inheritdoc} */ - public function drop($index) { + public function removeItem($index) { if (!is_numeric($index)) { throw new \InvalidArgumentException('Unable to drop a non-numeric delta.'); } @@ -180,17 +180,15 @@ public function first() { * Implements \ArrayAccess::offsetExists(). */ public function offsetExists($offset) { - // We do not want to throw exceptions here, so only use get() only when we - // are sure it will return. -// @todo: ask @fago why we need this getValue() !== NULL check to begin with ? - return isset($this->list) && array_key_exists($offset, $this->list) && $this->get($offset)->getValue() !== NULL; + // We do not want to throw exceptions here, so we do not use get(). + return isset($this->list[$offset]); } /** * Implements \ArrayAccess::offsetUnset(). */ public function offsetUnset($offset) { - $this->drop($offset); + $this->removeItem($offset); } /** @@ -224,14 +222,6 @@ public function appendItem($value = NULL) { } /** - * {@inheritdoc} - */ - public function clearItems() { - $this->list = array(); - return $this; - } - - /** * Helper for creating a list item object. * * @return \Drupal\Core\TypedData\TypedDataInterface diff --git a/core/modules/datetime/src/Tests/DateTimeItemTest.php b/core/modules/datetime/src/Tests/DateTimeItemTest.php index 2d76079..465326a 100644 --- a/core/modules/datetime/src/Tests/DateTimeItemTest.php +++ b/core/modules/datetime/src/Tests/DateTimeItemTest.php @@ -88,7 +88,7 @@ public function testSetValue() { // Test DateTimeItem::setValue() using string. $entity = entity_create('entity_test'); $value = '2014-01-01T20:00:00Z'; - $entity->field_datetime->value = $value; + $entity->get('field_datetime')->set(0, $value); $entity->save(); // Load the entity and ensure the field was saved correctly. $id = $entity->id(); @@ -98,7 +98,7 @@ public function testSetValue() { // Test DateTimeItem::setValue() using property array. $entity = entity_create('entity_test'); $value = '2014-01-01T20:00:00Z'; - $entity->field_datetime->value = $value; + $entity->set('field_datetime', $value); $entity->save(); // Load the entity and ensure the field was saved correctly. $id = $entity->id(); diff --git a/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php b/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php index 3a4432a..e7919f7 100644 --- a/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php +++ b/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php @@ -186,7 +186,7 @@ public function denormalize($data, $class, $format = NULL, array $context = arra // Remove any values that were set as a part of entity creation (e.g // uuid). If the incoming field data is set to an empty array, this will // also have the effect of emptying the field in REST module. - $items->clearItems(); + $items->setValue(array()); if ($field_data) { // Denormalize the field data into the FieldItemList object. $context['target_instance'] = $items;