Closed (fixed)
Project:
Entity API
Version:
7.x-1.x-dev
Component:
Core integration
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
11 Feb 2011 at 17:43 UTC
Updated:
1 Apr 2020 at 15:05 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
dave reidAh, the problem is when the text field can have multiple values. Then it gets no token. Otherwise if it's limited to one value for cardinality, then it gets a token. Not sure if this is by design or not.
Comment #2
dave reidComment #3
fagoIndeed, tokens for lists are currently missing. I took a stab on that.
Attached patch implements the tokens using the list<$type> notation as used else too + improves the code to the recently added label() method, via which also list values ala "value1, value2, value3" work.
E.g. the replacement in "title [node:title], All values: [node:field-tags] - a single value: [node:field-tags:1]" would work.
However, that way the code just goes and replace values for each "list" data type, what would pose problems if the token module would like to do it too (see #1047740: Add an [array:*] token type and a [user:roles] token). Maybe we could use the alter hook + add a check whether the token has been already replaced there?
Patch attached.
Comment #4
fagoComment #5
fagoThe generic list/array handling code should probably just go into the token module, though I guess we need something like the list<$type> notation so we have knowledge of the contained item type.
Comment #7
garethsprice commentedThis issue also appears when exposing tokens on Taxonomy Reference fields where more than one item can be selected.
Comment #8
fagoComment #9
wjaspers commentedsubbing.
Comment #10
TimelessDomain commentedpatch #3 works for taxonomy reference fields.
Comment #11
Jiri Volf commentedsubscribing
Comment #12
Hamid.D commentedsubscribing
Comment #13
dasjopatch doesn't apply correctly anymore
it seems the functionality at hunk #4 already got in by annother commit.
anyways, it works for me such that i can now use tokens for multi-terms in rules
Comment #14
dasjore-rolled the patch as stated above
Comment #15
casey commentedsub
Comment #16
BeaPower commentedsub
Comment #18
fago#14: entity_list_tokens_2.patch queued for re-testing.
Comment #19
muschpusch commentedCould this be related to: #1088538: OG (Organic Groups) tokens missing. ?
[edit]
To be a bit more specific: the og reference field (groups audience) is multi value list.
[/edit]
Comment #20
fagoyes
Comment #22
fagofinally came back to this one. In the meanwhile token.module got its 'array' type, but that doesn't fit for our list types as those don't have array keys - nor would it play with chaining list-item tokens.
Thus, attached patch adds token types for the entity api list types, i.e.
list<TYPE>+ implements token values for those lists. I also had a look at fixing #1183676: improve support for arbitrary data structures, though for a proper fix more work is needed (see issue). It basically works though: Tokens in data structures work, but are already specified as *dynamic* token and list possible properties in the help text.Attached patch works for me, e.g. using this test:
echo token_replace('[node:field-tags] - [node:field-tags:0] - [node:field-tags:1:url] - [node:field-image:alt] - [node:field-image:file:url] - [site:current-page:url]', array('node' => $node));We'll need test for that though.
Comment #23
dave reidThe array token type does have array keys, but does not yet support chaining. There is an open issue to add support for this in a way which will make the token UI allow those tokens to be listed in help as well: #1195874: Need to figure out how to create nested tokens from the array token type.
Comment #24
karens commentedI used the patch in #22 and tried to use [node:field-event-date:value2] in a pathauto token and it seems to work. Then I tried [node:field-event-date:value2:medium] and it gave me the error Fatal error: Call to undefined method EntityValueWrapper::language() in /../entity/entity_token.tokens.inc on line 268. Maybe the second wasn't expected to work yet.
So at this point I can set a token using Entity Tokens based on either value or value2 but I can't control its format.
Comment #25
fago@array-keys:
Yep, I know the 'array' type supports them. The entity api 'list' type is different though: it is defined as "list of values", thus it does not support the concept array keys. Still, those lists are represented as numerically indexed arrays, but they are by definition not like PHP arrays.
They 'array' type would perhaps match more for "entity api data structures", see #1183676: improve support for arbitrary data structures. Are there any plans on adding support for sub-tokens per token to token UI? I guess, best that would be implemented by additional data-type/token-type anyway. Maybe those should be hidden from the complete token UI listing though.
@Karen: Thanks for testing. Also the second use-case should work, you found a bug though. Attached patch should fix it, please test.
Comment #26
karens commentedWith that patch, trying to add a format after 'value' or 'value2' results in this error:
Fatal error: Call to a member function label() on a non-object in ../entity/entity_token.tokens.inc on line 285
Comment #27
fagook, I gave this a test too. Figured out there was still in issue with chaining in structs - attached patch fixes that. This certainly needs proper test-coverage ;)
Comment #28
karens commentedYay! that one works for me, at least for date tokens. Don't know what else to test.
Comment #29
mrfelton commentedI tried that patch in #27 trying to allow me to chain tokens through a Drupal Commerce product reference field to access properties of taxonomy terms associated with the related Drupal commerce product entity. After applying the patch I see a new line in the placeholder tokens fieldset:
So I tried a token of [node:field-product:product_id]. This resulted in a fatal eror:
Also, I was hoping to be able to get more from the related product entity than just the product id, such as the taxonomy terms associated with it. Will this patch eventually allow for deeper chaining, or would that need t be handled elsewhere, and if so, where? What is it that determines that only the product_id field will be accessible?
Comment #30
fagoThanks mrfelton for testing - I had a short look at it and noted that's caused by some incorrect property-info. See #1356006: Fix entity property info of product / customer profile / line item reference fields. With the patch over there it worked fine for me.
Apart from that, I've implemented tests, fixed tokens for not existing items to be correctly ignored and added an improvement to make use of token module's cached token info if available. Committed.
Comment #32
Hendry Lee commentedI tested this again with link field.
[node:field-link:0] gave the following result:
PHP Fatal error: Call to a member function value() on a non-object in /home/dev/www/sandbox.dev/sites/all/modules/contrib/entity/entity_token.tokens.inc on line 297
Comment #33
Hendry Lee commentedIf I entered [node:field-link], this is what I got on screen:
Property 0, Property 1
[node:field_link] displays the content right.
Comment #34
fagoPlease open a new issue for any follow-up problems.
Comment #35
crimsondryad commentedWe need this, any chance of a release anytime soon?
Comment #36
nguyentran commentedHello, i have the same problem as #33, i have tested with [node:field-link:0], [node:field-link:1], it does not work. Any help to solve this.
Thanks.
Comment #37
joshuautley commentedWe're working on a related solution due to a need to specify which value in a token array to display. Tried this as described with no luck.
An array with three values produces "Property 0, Property 1, Property 2"
Another thread is also having the same result > http://drupal.org/node/1440928
I'll see what the maintainer of the token module has to say.
Comment #38
mitchell commented#33, #36, #37: Please follow up on this in #1440928: Entity tokens for multi-value fields produce a fatal error.
Comment #39
mfoda commentedHas this issue been resolved in the 7.x1.0-rc3 or only in the current dev version?
Comment #40
klonos@mfoda: Hope I'm not too late to reply this question of yours Mohammad. Let's hope that this will be helpful to others too...
Back in #30 fago (the maintainer of Entity API) said that this issue here is supposed to be fixed by the commit in #1356006: Fix entity property info of product / customer profile / line item reference fields. That issue was closed as fixed with this commit. That dates 20 Dec 2011 and the 7.x-1.0 version of Entity API dates 25 Dec 2012, so the main issue should be fixed in 7.x-1.0. In fact -based on the release dates- the fix should actually exist since 7.x-1.0-rc2.
Now, I'm coming from #1103032: Document how to use date tokens where the Entity API is suggested as a solution for this, but I don't know if #1440928: Entity tokens for multi-value fields produce a fatal error makes it still an issue.
Comment #41
markusd1984 commentedHas anyone been able to use this successfully?
I went even back to Entity 7.x-1.2 with patch #44 yet still not working [event-node:field-datetime:0:value:custom:Y].
I also tried with Entity 7.x-1.9 and dev which seems to have this patch built in but no success, when using it in a rule to send a mail within the body I get no output at all.
Only [event-node:field-datetime] which outputs
Wed, 01/04/2020 - 18:00And [event-node:field_datetime] which outputs
22020-04-01 18:00:00 to 2020-04-01 18:30:00I want it similar to the way the field is displayed on the node
Wednesday, 1 April, 2020 - 18:00 to 18:30I looked through all issues in date and entity queues to no avail, including https://www.drupal.org/project/entity/issues/1440928.