Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / system / tests / modules / entity_test / src / Plugin / Field / ComputedReferenceTestFieldItemList.php
1 <?php
2
3 namespace Drupal\entity_test\Plugin\Field;
4
5 use Drupal\Core\Field\EntityReferenceFieldItemList;
6 use Drupal\Core\TypedData\ComputedItemListTrait;
7
8 /**
9  * A computed entity reference field item list.
10  */
11 class ComputedReferenceTestFieldItemList extends EntityReferenceFieldItemList {
12
13   use ComputedItemListTrait;
14
15   /**
16    * Compute the list property from state.
17    */
18   protected function computeValue() {
19     foreach (\Drupal::state()->get('entity_test_reference_computed_target_ids', []) as $delta => $id) {
20       $this->list[$delta] = $this->createItem($delta, $id);
21     }
22   }
23
24 }