diff --git a/core/lib/Drupal/Core/Field/FieldItemListComputed.php b/core/lib/Drupal/Core/Field/FieldItemListComputed.php deleted file mode 100644 index 30c076957a..0000000000 --- a/core/lib/Drupal/Core/Field/FieldItemListComputed.php +++ /dev/null @@ -1,65 +0,0 @@ -list = []; - $values = $this->computeItemValues(); - if (is_array($values) && !empty($values)) { - foreach ($values as $delta => $value) { - $this->list[] = $this->createItem($delta, $value); - } - } - } - - /** - * This should compute the values that are used to create the field items. - * - * @return array - * The values for the field items. - */ - protected abstract function computeItemValues(); - - /** - * This will do nothing as computed lists are readonly by default. - */ - public function setValue($values, $notify = TRUE) {} - - /** - * This will do nothing as computed lists are readonly by default. - */ - public function appendItem($value = NULL) {} - - /** - * This will do nothing as computed lists are readonly by default. - */ - public function defaultValuesForm(array &$form, FormStateInterface $form_state) {} - - /** - * This will do nothing as computed lists are readonly by default. - */ - public function removeItem($index) {} - - /** - * This will do nothing as computed lists are readonly by default. - */ - public function set($index, $value) {} - -} diff --git a/core/lib/Drupal/Core/Field/FieldItemListComputedInterface.php b/core/lib/Drupal/Core/Field/FieldItemListComputedInterface.php new file mode 100644 index 0000000000..e3f794fb08 --- /dev/null +++ b/core/lib/Drupal/Core/Field/FieldItemListComputedInterface.php @@ -0,0 +1,17 @@ +setContext($property_name, $object); if (isset($value)) { $property->setValue($value, FALSE); - } elseif ($property instanceof FieldItemListComputed) { - // populate the computed list with values as there are no initial values to set. - $property->computeItems(); + } + elseif ($property instanceof FieldItemListComputedInterface) { + // populate the computed list with values as there are no initial values + // to set. + $property->computeValue(); } return $property; } diff --git a/core/modules/field/tests/modules/field_computed_test/src/Plugin/Field/FieldType/DiceItemList.php b/core/modules/field/tests/modules/field_computed_test/src/Plugin/Field/FieldType/DiceItemList.php index 03aca20992..004440b409 100644 --- a/core/modules/field/tests/modules/field_computed_test/src/Plugin/Field/FieldType/DiceItemList.php +++ b/core/modules/field/tests/modules/field_computed_test/src/Plugin/Field/FieldType/DiceItemList.php @@ -2,16 +2,33 @@ namespace Drupal\field_computed_test\Plugin\Field\FieldType; -use Drupal\Core\Field\FieldItemListComputed; +use Drupal\Core\Field\FieldItemList; +use Drupal\Core\Field\FieldItemListComputedInterface; /** * Represents a configurable dice result. */ -class DiceItemList extends FieldItemListComputed { +class DiceItemList extends FieldItemList implements FieldItemListComputedInterface { /** * {@inheritdoc} */ + public function computeValue() { + $this->list = []; + $values = $this->computeItemValues(); + if (is_array($values) && !empty($values)) { + foreach ($values as $delta => $value) { + $this->list[] = $this->createItem($delta, $value); + } + } + } + + /** + * This should compute the values that are used to create the field items. + * + * @return array + * The values for the field items. + */ protected function computeItemValues() { $items_count = $this->getEntity()->field_dice_count->value; $values = [];