_entity_token_get_token does not handle text_formatted fields.

The following try doesn't work:
--- a/docroot/sites/all/modules/contrib/entity/entity_token.tokens.inc
+++ b/docroot/sites/all/modules/contrib/entity/entity_token.tokens.inc
@@ -325,6 +325,8 @@ function _entity_token_get_token($wrapper, $options) {
case 'uri':
case 'text':
return $wrapper->value($options);
+ case 'text_formatted':
+ return $wrapper->value()['value'];
}

How can I support struct values?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lokapujya’s picture

Partially fixed by #1621084: Support list<struct> type tokens. But the patch needs more work. I used two formatted text tokens in a rules email. One of the two is fixed. The other is now blank.

lokapujya’s picture

I have two filtered text fields. One of them is being treated as type text, and the other is being treated as a struct. The one that is treated as a struct is working. Not sure why the other one is treated as text.

lokapujya’s picture

The issue is that I used the same field in two different content types. In one content type it is text, in another it is text_formatted. So, once the field gets loaded as text, it must get cached and then the second content type doesn't get loaded as text_formatted. I worked around the bug, by making both fields text_formatted.

geoffreyr’s picture

Turned this one into a patchfile because I found it useful.

lokapujya’s picture

Status: Active » Needs review

This module has automated tests. I wonder what happens with this patch. Will try to kick it off.

lokapujya’s picture

+++ b/entity_token.tokens.inc
@@ -327,6 +327,8 @@ function _entity_token_get_token($wrapper, $options) {
+      return $wrapper->value()['value'];

Not sure if this is even overall the right solution. But if the code is used, I guess that since we have to support PHP 5.3, it should use a tmp variable:

$value = $wrapper->value();
return value['value'];