Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
How is it possible to use token replacement for a text_formatted data type?
I tried to implement hook_rules_evaluator_info_alter() and add text_formatted to the supported types, but that won't solve the problem because token_scan() expects a string.
Comments
Comment #1
sgabe CreditAttribution: sgabe commentedIt seems the PHP evaluation also not works for text_formatted data type. I would like to know if there is a solution or these features are only available for text data type.
Changing title to better reflect the problem.
Comment #2
fagoIndeed, for that to work we need to special case the replacement code to replace tokens in $data_value['value].
Comment #3
sgabe CreditAttribution: sgabe commentedThe same applies to the PHP evaluation? (It needs to be and will be solved in Rules?)
Comment #4
butler360 CreditAttribution: butler360 commentedSubscribing.
Edit: Just noticed the new "Follow" button. Oops.
Comment #5
mitchell CreditAttribution: mitchell commentedUpdated component.
Comment #6
sgabe CreditAttribution: sgabe commented#1667482: Send a text field value as an HTML mail via Rules is marked as a duplicate of this.
Comment #7
Torenware CreditAttribution: Torenware commentedWould you folks allow a patch on this?
I've spent some time wandering through the token processing code in rules; it may not be that hard to do this.
Comment #8
willieseabrook CreditAttribution: willieseabrook commentedNot sure if this is the right issue to place this, but #1667482: Send a text field value as an HTML mail via Rules is marked as a duplicate of this, and it's similar to my problem.
I have two fields:
1. Message::args!myargument
2. Message:emailbody
I'm trying to take emailbody, which is an HTML field with a "Full HTML" filter and use it to set the value of the argument !myargument, which is also a field with a "Full HTML" filter.
This doesn't work - the HTML in emailbody is stripped during the set action. I've found where it occures:
The key is the line "$value = $entry->value($options);"
This is where $value, which used to be HTML, comes out plain text.
We see two lines basically saying HTML is banned:
Why?
$entry is of type EntityValueWrapper, so we look deeper:
Particularly:
We can see that I'm either allowed check_plain or strip_tags, but certainly not HTML.
What to do? I need to be able to set an HTML field, and I can't figure out what hook to use. I don't see anywhere where I can override the use of EntityValueWrapper for just my field and make a GiveMeHTMLEntityValueWrapper class.
Nor does the logic appear to allow me to change $options.
So, how do I set/get an HTML field without nuking the HTML? Again, apologies if this is the wrong issue, but the duplicate did appear to be very similar.
Comment #9
willieseabrook CreditAttribution: willieseabrook commented#1814922: Rule sanitizes the $body if populated by a parameter
Related?
Comment #10
willieseabrook CreditAttribution: willieseabrook commentedFor now, I've used the following hack. So I can continue dev until I figure this out more.
Comment #11
smokrisHere's an attempt to add token support for text_formatted.
(I've also attached an extra patch that applies to 7.x-2.2.)
Comment #13
KimmoT CreditAttribution: KimmoT commentedI have another temporary solution for this. I used plaintext for creating the html with replaced tokens and used a custom action for passing the values as formatted text:
Comment #14
kopeboy CreditAttribution: kopeboy commentedUpdates?
I am here because I would like to send a rendered entity in an email with Rules.
I am using Mandrill, and already sending HTML emails, the problem is Rules won't let me select the entity and view mode but only text fields of the entity in the email body.
Comment #15
Arjandew CreditAttribution: Arjandew commentedhmm the php replacement work as expected.
But the normal token replacement is not working in rules.
got it working to use the following replacement
?>
Now i can use formatted_text variable in rules :)
Comment #16
delacosta456 CreditAttribution: delacosta456 commented@KimmoT
In rules After creating the using plaintext to creating the html wit replaced token ... you can add one more action of "Set data value" of the (your)text_formated field by making that you choose like below
node:field-(your)text_formated:format Please notice the "format" at the end.