I'm writing a rule to send a message about a new order (the site is built using Drupal Commerce). I want to include the total order amount in the message body. I see the needed datum in the data selection mode, but I can't access it in the direct input mode.

As I understand, in direct input mode the entered value is piped through the token replacement mechanism. But what the data selection mode is about?

Can anyone give some hints or point me to relevant materials.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rszrama’s picture

Title: Please, explain the difference between "data selection" and "direct" input modes » How can I use a field token for an entity variable in a textarea?

The difference is that data selection mode lets you choose the value for whatever parameter it is you're setting from the properties of a variable available to the Rule. Direct input mode lets you put in whatever you want as the value (without the constraints of the data type). The reason you don't see the order total token is because it's actually a field on the order variable, and the replacement patterns available to you do not generally include field data.

So, a better question for you would be how can you use a field token in a textarea for the body of an e-mail.

akamaus’s picture

> So, a better question for you would be how can you use a field token in a textarea for the body of an e-mail.
Well, I know token contrib module in D7 provides tokens for entity fields. I used it with the rules in the past for accessing fields of a node. But looks like it doesn't work in this case.

Being able to include the order total amount in the notification email looks like a nice usability improvement for me. But right now I can't wrap my head around all this stuff :)

fago’s picture

>Well, I know token contrib module in D7 provides tokens for entity fields. I used it with the rules in the past for accessing fields of a node. But looks like it doesn't work in this case.

Actually it's the entity API "entity tokens" module that does that. However, it currently does not cover generating tokens for fields that define a data-structure as property info. Also there is an issue for supporting multiple values in the entity api queue.

das-peter’s picture

Project: Rules » Entity API
Version: 7.x-2.0-beta1 » 7.x-1.x-dev
Component: Rules Engine » Entity tokens
Category: support » feature
Status: Active » Needs review
FileSize
2.71 KB

Hi, I just struggled with this too.
I've created attached patch as workaround - and it seems to work. However, I've tested only roughly (Yes, in my case as well to send the order-confirmations of commerce ;) ).
And I guess there could be a more elegant solution by use some kind of recursive construct.
Nevertheless I wont hold back the patch :)

das-peter’s picture

Fix for description.

fago’s picture

Status: Needs review » Needs work

I don't think we should do that specifically for fields, as it is general problem for data-wrappers using structs. So let's solve it for structs in general.

I think best, we define a new token-type "entity-struct-wrapped" or so, which contains a wrapper as data value. That way can pass through the wrapper in token directly, what should make it easy to generate the token value.

fago’s picture

Title: How can I use a field token for an entity variable in a textarea? » support tokens for arbitrary data structures
zhangtaihao’s picture

I think Rules does it fantastically well. I guess we'd adapt the data selector values from Rules to Entity tokens.

carn1x’s picture

subscribe

fago’s picture

Title: support tokens for arbitrary data structures » improve support for arbitrary data structures

The patch in #1058856-22: Entity tokens not created for multi-value fields basically fixes this issue too. It does not properly register tokens for each data property of a structure though, as for that we'd need register a token-type. Currently, the properties of a data structure may differ by data structure (e.g. per field) though. Thus, the basic fix from #1058856 just lists some possible property-keys in the help text.

For a proper fix, we'd need a proper hook for defining compound data structures. Thus we'd have a central place for registering properties of the data structure + properly registered names. That could also be much needed by rules which currently has to complement entity-api data types on its own, as well as by other modules like wsclient.
Based upon this defined compound data structures, we could easily add proper token support for those. Still, for backward compability we should keep the current per-property 'property info' key.

guillaumev’s picture

Hi,

Any update on this ?

I'm trying to do what's in this issue: http://drupal.org/node/1262904 (i e concatenate the content of 2 variables in a direct input mode) and, even when updating to entity dev, it doesn't seem to be working...

mitchell’s picture

Status: Needs work » Postponed (maintainer needs more info)

The issue referenced in #10 is fixed. Is #1547160: Support variable substitution in direct input mode the next step for this?

mitchell’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)