Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / system / tests / modules / entity_test / src / TypedData / ComputedString.php
diff --git a/web/core/modules/system/tests/modules/entity_test/src/TypedData/ComputedString.php b/web/core/modules/system/tests/modules/entity_test/src/TypedData/ComputedString.php
new file mode 100644 (file)
index 0000000..a817526
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+namespace Drupal\entity_test\TypedData;
+
+use Drupal\Core\Cache\Cache;
+use Drupal\Core\Cache\CacheableDependencyInterface;
+use Drupal\Core\TypedData\TypedData;
+
+/**
+ * A computed property for test strings.
+ */
+class ComputedString extends TypedData implements CacheableDependencyInterface {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getValue() {
+    /** @var \Drupal\Core\Field\FieldItemInterface $item */
+    $item = $this->getParent();
+    $computed_value = "Computed! " . $item->get('value')->getString();
+
+    return $computed_value;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCastedValue() {
+    return $this->getString();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCacheTags() {
+    return ['you_are_it', 'no_tag_backs'];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCacheContexts() {
+    return ['request_format'];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCacheMaxAge() {
+    return Cache::PERMANENT;
+  }
+
+}