class ComputedTestFieldItemList

Same name and namespace in other branches
  1. 11.x core/modules/system/tests/modules/entity_test/src/Plugin/Field/ComputedTestFieldItemList.php \Drupal\entity_test\Plugin\Field\ComputedTestFieldItemList
  2. 10 core/modules/system/tests/modules/entity_test/src/Plugin/Field/ComputedTestFieldItemList.php \Drupal\entity_test\Plugin\Field\ComputedTestFieldItemList
  3. 8.9.x core/modules/system/tests/modules/entity_test/src/Plugin/Field/ComputedTestFieldItemList.php \Drupal\entity_test\Plugin\Field\ComputedTestFieldItemList

A computed field item list.

Hierarchy

Expanded class hierarchy of ComputedTestFieldItemList

1 file declares its use of ComputedTestFieldItemList
EntityTestComputedField.php in core/modules/system/tests/modules/entity_test/src/Entity/EntityTestComputedField.php

File

core/modules/system/tests/modules/entity_test/src/Plugin/Field/ComputedTestFieldItemList.php, line 11

Namespace

Drupal\entity_test\Plugin\Field
View source
class ComputedTestFieldItemList extends FieldItemList {
  use ComputedItemListTrait;
  
  /**
   * Compute the list property from state.
   */
  protected function computeValue() {
    // Count the number of times this method has been executed during the
    // lifecycle of an entity.
    $execution_count = \Drupal::state()->get('computed_test_field_execution', 0);
    \Drupal::state()->set('computed_test_field_execution', ++$execution_count);
    foreach (\Drupal::state()->get('entity_test_computed_field_item_list_value', []) as $delta => $item) {
      $this->list[$delta] = $this->createItem($delta, $item);
    }
  }

}

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