Namespace
Drupal\entity_test\Plugin\Field
File
core/modules/system/tests/modules/entity_test/src/Plugin/Field/ComputedTestCacheableIntegerItemList.php
View source
<?php
namespace Drupal\entity_test\Plugin\Field;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Cache\CacheableDependencyTrait;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Field\FieldItemList;
use Drupal\Core\TypedData\ComputedItemListTrait;
class ComputedTestCacheableIntegerItemList extends FieldItemList implements CacheableDependencyInterface {
use CacheableDependencyTrait, ComputedItemListTrait;
protected function computeValue() {
$value = \Drupal::state()
->get('entity_test_computed_integer_value', 0);
$item = $this
->createItem(0, $value);
$cacheability = (new CacheableMetadata())
->setCacheContexts([
'url.query_args:computed_test_cacheable_integer_field',
])
->setCacheTags([
'field:computed_test_cacheable_integer_field',
])
->setCacheMaxAge(31536000);
$this
->setCacheability($cacheability);
$this->list[0] = $item;
}
}
Classes