.../src/JsonApiComputedFieldItemList.php | 2 +- .../src/Plugin/DataType/CacheableStringData.php | 20 +++++--------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/tests/modules/jsonapi_test_computed_field/src/JsonApiComputedFieldItemList.php b/tests/modules/jsonapi_test_computed_field/src/JsonApiComputedFieldItemList.php index 2f21edf..bf1001d 100644 --- a/tests/modules/jsonapi_test_computed_field/src/JsonApiComputedFieldItemList.php +++ b/tests/modules/jsonapi_test_computed_field/src/JsonApiComputedFieldItemList.php @@ -23,7 +23,7 @@ class JsonApiComputedFieldItemList extends FieldItemList { ->setCacheContexts(['url.query_args:jsonapi_test_computed_field']) ->setCacheTags(['field:jsonapi_test_computed_field']) ->setCacheMaxAge(800); - $item->get('value')->setCacheability($cacheability); + $item->get('value')->addCacheableDependency($cacheability); $this->list[0] = $item; } diff --git a/tests/modules/jsonapi_test_computed_field/src/Plugin/DataType/CacheableStringData.php b/tests/modules/jsonapi_test_computed_field/src/Plugin/DataType/CacheableStringData.php index a9949f0..ad32cec 100644 --- a/tests/modules/jsonapi_test_computed_field/src/Plugin/DataType/CacheableStringData.php +++ b/tests/modules/jsonapi_test_computed_field/src/Plugin/DataType/CacheableStringData.php @@ -2,9 +2,9 @@ namespace Drupal\jsonapi_test_computed_field\Plugin\DataType; -use Drupal\Core\Cache\CacheableDependencyInterface; -use Drupal\Core\Cache\CacheableDependencyTrait; -use Drupal\Core\TypedData\Plugin\DataType\StringData; +use Drupal\Core\Cache\RefinableCacheableDependencyInterface; +use Drupal\Core\Cache\RefinableCacheableDependencyTrait; +use Drupal\Core\TypedData\TypedData; /** * The string data type with cacheablity metadata. @@ -17,18 +17,8 @@ use Drupal\Core\TypedData\Plugin\DataType\StringData; * label = @Translation("Cacheable String") * ) */ -class CacheableStringData extends StringData implements CacheableDependencyInterface { +class CacheableStringData extends TypedData implements RefinableCacheableDependencyInterface { - use CacheableDependencyTrait; - - /** - * {@inheritdoc} - */ - public function setCacheability(CacheableDependencyInterface $cacheability) { - $this->cacheContexts = $cacheability->getCacheContexts(); - $this->cacheTags = $cacheability->getCacheTags(); - $this->cacheMaxAge = $cacheability->getCacheMaxAge(); - return $this; - } + use RefinableCacheableDependencyTrait; }