I am trying to understand how the token system in Drupal 8 interacts with the cache bubbling system and in LinkFormatter I see $link_title = \Drupal::token()->replace($item->title, [$entity->getEntityTypeId() => $entity], ['clear' => TRUE]); doesn't pass in a BubbleableMetadata object to the token system. But why?

1 Answer 1


Is this causing a bug for you, or are you just trying to understand how it works at all?

Making the token system integrate with the cache system happened very late in the Drupal 8 development cycle (see https://www.drupal.org/node/2528662).

Note that if that optional Token::replace(…, …, …, BubbleableMetadata $bubbleable_metadata = NULL) argument is not passed, it does check whether this token replacement is happening within an active render context (see the hasRenderContext() condition in ::replace()) and if so, it bubbles it automatically, directly onto the render context. Since Linkformatter::viewElements() is only ever called during rendering, AFAICT it should actually be working fine already, thanks to that automatic bubbling. We should not be relying on that, but precisely because it was added so late in the D8 development cycle, we had no choice but to resort to such approaches to minimize disruption.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.