function ComputedTestCacheableIntegerItemList::computeValue

Same name and namespace in other branches
  1. 11.x core/modules/system/tests/modules/entity_test/src/Plugin/Field/ComputedTestCacheableIntegerItemList.php \Drupal\entity_test\Plugin\Field\ComputedTestCacheableIntegerItemList::computeValue()

File

core/modules/system/tests/modules/entity_test/src/Plugin/Field/ComputedTestCacheableIntegerItemList.php, line 25

Class

ComputedTestCacheableIntegerItemList
Item list class for computed cacheable string field.

Namespace

Drupal\entity_test\Plugin\Field

Code

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;
}

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