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,
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3037538-create-all-token-for-limited-multi-value-field.patch | 923 bytes | ashrafomar |
Issue fork token-3037538
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
c.e.a commentedComment #3
ashrafomar commentedThere 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
Comment #4
ressaThe 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?
Comment #7
sriram_s commentedHey, 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!
Comment #8
csakiistvanComment #9
csakiistvanEnvironment
Prerequisites
Steps
ddev drush crExpected results
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.