Add cacheability metadata for [current-date] tokens

Created on 1 May 2025, 11 days ago

Problem/Motivation

Outputting something with [current-date:custom:Y] should make sure that the cacheability metadata expires when the year changes.

Steps to reproduce

use Drupal\Core\Render\BubbleableMetadata;

$metadata = new BubbleableMetadata();
$result = \Drupal::token()->replace('The current month is [current-date:custom:F]', [], [], $metadata);
echo $result . "\n";
echo "Max-age: " . $metadata->getCacheMaxAge();

Currently this outputs:

The current month is May
Max-age: -1

Proposed resolution

Let's attempt to add cacheability metadata based on the format being used in the token.

The max age in our example should be the value until June 1, 00:00:00.

Remaining tasks

User interface changes

None

API changes

None

Data model changes

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States dave reid Nebraska USA

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024