ComputedReferenceTestFieldItemList.php

Same filename and directory in other branches
  1. 9 core/modules/system/tests/modules/entity_test/src/Plugin/Field/ComputedReferenceTestFieldItemList.php
  2. 8.9.x core/modules/system/tests/modules/entity_test/src/Plugin/Field/ComputedReferenceTestFieldItemList.php
  3. 10 core/modules/system/tests/modules/entity_test/src/Plugin/Field/ComputedReferenceTestFieldItemList.php

Namespace

Drupal\entity_test\Plugin\Field

File

core/modules/system/tests/modules/entity_test/src/Plugin/Field/ComputedReferenceTestFieldItemList.php

View source
<?php

namespace Drupal\entity_test\Plugin\Field;

use Drupal\Core\Field\EntityReferenceFieldItemList;
use Drupal\Core\TypedData\ComputedItemListTrait;

/**
 * A computed entity reference field item list.
 */
class ComputedReferenceTestFieldItemList extends EntityReferenceFieldItemList {
    use ComputedItemListTrait;
    
    /**
     * Compute the list property from state.
     */
    protected function computeValue() {
        foreach (\Drupal::state()->get('entity_test_reference_computed_target_ids', []) as $delta => $id) {
            $this->list[$delta] = $this->createItem($delta, $id);
        }
    }

}

Classes

Title Deprecated Summary
ComputedReferenceTestFieldItemList A computed entity reference field item list.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.