Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / system / tests / modules / entity_test / src / Plugin / Field / ComputedTestFieldItemList.php
diff --git a/web/core/modules/system/tests/modules/entity_test/src/Plugin/Field/ComputedTestFieldItemList.php b/web/core/modules/system/tests/modules/entity_test/src/Plugin/Field/ComputedTestFieldItemList.php
new file mode 100644 (file)
index 0000000..0dfa3e1
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+
+namespace Drupal\entity_test\Plugin\Field;
+
+use Drupal\Core\TypedData\ComputedItemListTrait;
+use Drupal\Core\Field\FieldItemList;
+
+/**
+ * A computed field item list.
+ */
+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);
+    }
+  }
+
+}