I have a multi-value image field (Food images) limited to "8" images on the user entity.

The token tree is showing only the 3 tokens for the 3 images as below:

Food images	                        Entity reference field.
Food images type with delta 0	[current-user:field_user_food_images:0:target_id]
Food images type with delta 1	[current-user:field_user_food_images:1:target_id]
Food images type with delta 2	[current-user:field_user_food_images:2:target_id]

But I was expecting to see something like below:

Food images	                        Entity reference field.
Food images type with delta 0	[current-user:field_user_food_images:0:target_id]
Food images type with delta 1	[current-user:field_user_food_images:1:target_id]
Food images type with delta 2	[current-user:field_user_food_images:2:target_id]
Food images type with delta 3	[current-user:field_user_food_images:3:target_id]
Food images type with delta 4	[current-user:field_user_food_images:4:target_id]
Food images type with delta 5	[current-user:field_user_food_images:5:target_id]
Food images type with delta 6	[current-user:field_user_food_images:6:target_id]
Food images type with delta 7	[current-user:field_user_food_images:7:target_id]

Because when I use the token [current-user:field_user_food_images:3:target_id], it return an error: Token not valid

any help about what is going on here ?

Thank you,

Issue fork token-3037538

Command icon 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

C.E.A created an issue. See original summary.

c.e.a’s picture

Issue summary: View changes
ashrafomar’s picture

There is a hard-coded limit number (3) for all unlimited and limited multi-value field, so I only applied 3 for unlimited and set the limited but multi-value field value to use whatever values is set

ressa’s picture

The problem is that only a single value from a multivalue field is being output, like from a taxonomy term Tag field.

How can you output all values?

sriram s made their first commit to this issue’s fork.

sriram_s’s picture

Status: Active » Needs review

Hey, thanks for the patch back in #3 @ashrafomar — you had the right idea, the hard-coded limit of 3 was exactly the problem. I went ahead and re-rolled it since the code moved from token.tokens.inc into TokenTokenInfoHooks.php at some point and the old patch doesn't apply anymore. Opened a new MR with basically the same fix plus a test.

@ressa saw your comment too — outputting all the values already works fine with the plain [node:field_tags] token, and you can reference any delta directly even if it's not listed in the tree, so that part should be covered already. I kept this MR focused on just the tree listing since that's what the issue was originally about, happy to look at the output side separately if it's still an issue for you.

Let me know if anything needs tweaking!

csakiistvan’s picture

Assigned: Unassigned » csakiistvan
csakiistvan’s picture

Assigned: csakiistvan » Unassigned
Status: Needs review » Reviewed & tested by the community

Environment

  • Drupal: 11.4.4
  • PHP: 8.5.5
  • Database: MariaDB 10.11.16
  • DDEV: v1.25.2
  • Token: 8.x-1.17

Prerequisites

  • Create a multi-value field with a limited cardinality greater than 3 (e.g. cardinality 5) on any fieldable entity bundle.

Steps

  1. Apply the fix from MR !132: stop hardcoding the delta token list to a maximum of 3 for fields with a limited cardinality, only cap the preview at 3 for fields with unlimited cardinality.
  2. Rebuild caches: ddev drush cr
  3. Inspect the token info for the field's list type and confirm a delta token is listed for every value up to the field's cardinality.

Expected results

  • For a limited multi-value field (e.g. cardinality 5), the token tree lists one delta token per value (deltas 0 through 4).
  • For an unlimited multi-value field, the token tree still only previews the first 3 deltas, since they cannot be fully enumerated.

Actual results

Before the fix, a limited multi-value field with cardinality 5 only listed delta tokens 0, 1 and 2 in the token tree, hiding deltas 3 and 4 entirely (tokens for those deltas still worked if typed manually, but were undiscoverable). After applying the fix, all 5 delta tokens (0 through 4) were listed as expected.


Testing produced with the assistance of an LLM.