class ComputedTestCacheableIntegerItemList

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
  2. 10 core/modules/system/tests/modules/entity_test/src/Plugin/Field/ComputedTestCacheableIntegerItemList.php \Drupal\entity_test\Plugin\Field\ComputedTestCacheableIntegerItemList

Item list class for computed cacheable string field.

This class sets the cacheable metadata on the field item list directly.

Hierarchy

Expanded class hierarchy of ComputedTestCacheableIntegerItemList

See also

\Drupal\entity_test\Plugin\Field\ComputedTestCacheableStringItemList

1 file declares its use of ComputedTestCacheableIntegerItemList
EntityTestComputedField.php in core/modules/system/tests/modules/entity_test/src/Entity/EntityTestComputedField.php

File

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

Namespace

Drupal\entity_test\Plugin\Field
View source
class ComputedTestCacheableIntegerItemList extends FieldItemList implements CacheableDependencyInterface {
  use CacheableDependencyTrait, ComputedItemListTrait;
  
  /**
   * {@inheritdoc}
   */
  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.