Problem/Motivation

When there are multiple date values (either repeating or just multiple, single dates), formatted tokens that are defined in smart_date.tokens.inc all return a value based on delta 0 rather than the delta that is being referenced.

Steps to reproduce

Print out token values in the node template for a content type with a smart date field. For example, this template code:

{{ drupal_token('node:field_when:0:value', {node}) }}
{{ drupal_token('node:field_when:0:format:default', {node}) }}
{{ drupal_token('node:field_when:1:value', {node}) }}
{{ drupal_token('node:field_when:1:format:default', {node}) }}
{{ drupal_token('node:field_when:2:value', {node}) }}
{{ drupal_token('node:field_when:2:format:default', {node}) }}

Produces this output:

1725638400
Fri, Sep 6 2024, 11am - 12pm
1726243200
Fri, Sep 6 2024, 11am - 12pm
1726848000
Fri, Sep 6 2024, 11am - 12pm
1727452800
Fri, Sep 6 2024, 11am - 12pm

The 'value' tokens are correct, but the 'format:default' tokens are all returning delta 0 values.

Comments

brian.barry@utexas.edu created an issue.

brian.barry@utexas.edu’s picture

Following up on this, I boiled it down to a minimal install.

Steps to reproduce

Install Drupal 10.3.10
Install module Smart Date 4.2.1
Install module Token 8.x-1.15
Install module Twig Tweak 3.4.0
Create content type with Smart Date field (field_when)
Insert code into node.html.twig template:

value - {{ drupal_token('node:field_when:0:value', {node}) }}<br>
format:default - {{ drupal_token('node:field_when:0:format:default', {node}) }}<br>
value - {{ drupal_token('node:field_when:1:value', {node}) }}<br>
format:default - {{ drupal_token('node:field_when:1:format:default', {node}) }}<br>
value - {{ drupal_token('node:field_when:2:value', {node}) }}<br>
format:default - {{ drupal_token('node:field_when:2:format:default', {node}) }}<br>

In this case I created a node with only two date values, but invoking a formatted token for delta 2, which is empty, still returns the value of delta 0.

value - 1733572800
format:default - Sat, Dec 7 2024, 6 - 7am
value - 1733659200
format:default - Sat, Dec 7 2024, 6 - 7am
value - [node:field_when:2:value]
format:default - Sat, Dec 7 2024, 6 - 7am