I wrote an unserialize action for the rules_data_transform module, which returns an associative array.

It seems like the system is only set up to handle numbered arrays though, and I can't work out how to access any of the array items with tokens/data selectors, it only seems to work if I convert to an indexed array.

If I try a token such as [array:key] it doesn't get replaced, if I use [array:index] (e.g. [array:0] I get a fatal error:

Fatal error: Call to undefined method EntityValueWrapper::get() in C:\xampp\htdocs\x\sites\all\modules\entity\entity_token.tokens.inc on line 222

After applying the patch in this issue #1440928: Entity tokens for multi-value fields produce a fatal error the fatal error goes away, replaced with these notices:

Notice: Undefined index: text in entity_token_tokens() (line 220 of C:\xampp\htdocs\x\sites\all\modules\entity\entity_token.tokens.inc).
Notice: Undefined variable: property_name in entity_token_tokens() (line 222 of C:\xampp\htdocs\x\sites\all\modules\entity\entity_token.tokens.inc).

But still doesn't work. Am I barking up the wrong tree here (have a mistaken idea), or should this be possible? Apologies if this is more to do with rules than Entity API - wasn't sure which module to submit the issue to.

Comments

jantoine’s picture

Category: Support request » Bug report
Status: Active » Needs review
StatusFileSize
new1.79 KB

I have run into this same problem and it seems to stem from some confusion as to whether a list should be defined as list<$entity_type> or list<$token_type>. Rules demands the former, so I'll assume that is the correct format. It appears however, that the entity_token_tokens() function assumes the latter. Patch attached that corrects entity_token_tokens() to assume the former.

Status: Needs review » Needs work

The last submitted patch, 1: entity_token-entity-types-2126215-1.patch, failed testing.

xamanu’s picture

It is not recomendable to apply this patch, as this breaks other stuff. In my case, the pathauto generation of urls based on tokens. Using the newest version 1.5 all works fine and it seems to make this issue here obsolete.

Can you confirm this?

jantoine’s picture

I am no longer using this patch but the functionality I wrote it for continues to work, so I must have removed it from my project after updating to Entity API 1.5, but neglected to come back and comment on this issue. I think this should be marked as fixed and closed!

jgullstr’s picture

Status: Needs work » Needs review
StatusFileSize
new699 bytes

I believe the underlying problem here is that lists are expected to consist of chained token types. If an entity property type is, for example, "list<text>", entity_token_tokens() can't wrap the data properly, as $token_types['text'] is not set.
This can be prevented by including the additional token types available from entity_token_types() when evaluating tokens for "list<type>" properties.

Attached patch reloads $token_types using entity_token_types() to make missing token types available for lists.

jgullstr’s picture

Title: Tokens don't work with associative arrays in rules » Allow lists of unchained token types.
jgullstr’s picture

Title: Allow lists of unchained token types. » Support lists of non-chained token types
StatusFileSize
new1.1 KB

Faster, slightly less readable approach attached.

jgullstr’s picture

This fork of the message module illustrates a use case that needs this patch.

I've added a list property to the Message entity. Without #7, I get the "Fatal error: Call to undefined method EntityValueWrapper::get()", with the patch applied everything works fine.

jgullstr’s picture

Version: 7.x-1.2 » 7.x-1.x-dev

osopolar’s picture

This works for me using a text field token like [node:field-text:0].

BTW: It does not work with [node:field-text:0:value] on this field, which is not correct, but should not result in a fatal error.

@xamanu: What exactly did not work while using patch in #1 (maybe this is still valid)? Therefore no RTBC yet.

jgullstr’s picture

Patch in #7 only extends available tokens in case $token_types[$item_token_type] is not set. As current implementation assumes that $token_types[$item_token_type] exists, the additional cases made available by this patch will produce errors already, hence nothing that is not already broken will break.

chris matthews’s picture

Status: Needs review » Needs work