Adjust caching logic of FieldReuseAccessCheck::access()

Created on 10 May 2024, 8 months ago

Problem/Motivation

The logic of RefinableCacheableDependencyTrait::addCacheableDependency() has been updated in #3232018: Trigger an error when using \Drupal\Core\Cache\RefinableCacheableDependencyTrait::addCacheableDependency with a non CacheableDependencyInterface object .

If the passed object is NOT an instance of CacheableDependencyInterface
Previous behavior: max-age is set to 0
Future behavior: an exception is thrown

In order to get rid of the deprecation notice and preserve the old behavior, one bit of FieldReuseAccessCheck::access() code was changed from

$access->addCacheableDependency($this->entityFieldManager);

to

if ($this->entityFieldManager instanceof CacheableDependencyInterface) {
  $access->addCacheableDependency($this->entityFieldManager);
}
else {
  $access->setCacheMaxAge(0);
}

However, it isn't clear if this is correct because the if condition always resolves to FALSE because EntityFieldManager isn't a cacheable dependency.

It seems that either the above code needs to be removed completely, or it should be replaced with $access->setCacheMaxAge(0).

Steps to reproduce

Proposed resolution

Remaining tasks

- Make a decision
- Update the code

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

📌 Task
Status

Active

Version

11.0 🔥

Component
Field UI 

Last updated 10 days ago

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024