ComputedString.php in Drupal 9
File
core/modules/system/tests/modules/entity_test/src/TypedData/ComputedString.php
View source
<?php
namespace Drupal\entity_test\TypedData;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\TypedData\TypedData;
class ComputedString extends TypedData implements CacheableDependencyInterface {
public function getValue() {
$item = $this
->getParent();
$computed_value = "Computed! " . $item
->get('value')
->getString();
return $computed_value;
}
public function getCastedValue() {
return $this
->getString();
}
public function getCacheTags() {
return [
'you_are_it',
'no_tag_backs',
];
}
public function getCacheContexts() {
return [
'request_format',
];
}
public function getCacheMaxAge() {
return Cache::PERMANENT;
}
}