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.
Issue fork smart_date-3492003
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
brian.barry@utexas.edu commentedFollowing 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:
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
Comment #3
nattsThe delta part preceding any of smart_date's tokens is checked for, but then discarded, hence always defaulting to zero (the first item).
So I've updated this to either use the delta (if given), or default to zero.
Here's the patch for temporary use until this gets released.
---
natts made their first commit to this issue’s fork.
Comment #5
nattsComment #6
mandclu commentedComment #8
mandclu commentedThanks for the work here. Merged into the 4.3.x branch.