1

In Drupal 7, I have defined a new content type which has a checkbox field . The idea is that when a user chooses option A and submits the content, the system does something after the creation of the node, say, send an email to the webmaster and if the user choose option B or C while creating the content, the system do nothing.

I've had difficulty to expose the select field result to a Rules Condition and I'm even not sure whether it is possible, so appreciate your help.

2 Answers 2

4

Well, I found my answer:

I need to create a 'Entity has field' condition and equate it to the machine name of the field in question.

Then the field becomes exposed in 'Data Comparison' to be evaluated.

0

Your own answer is correct, but a bit cryptic IMO.

By adding a Rules Condition Entity has field (related to your field) it becomes available to use it in subsequent Rules Conditions, and also subsequent Rules Actions. That's also what is mentioned in the Rules UI when you're adding a "data comparison" condition: somewhere it says "The data selector helps you drill down into the data available to Rules. To make entity fields appear in the data selector, you may have to use the condition 'entity has field' (or 'content is of type')".

For a video tutorial that illustrates the importance of this Entity has field condition, refer to Data types and data selection, especially what is shown between about 13:30 and 17:30 in it.

Example

Have a look at this Rules example in Rules Export format (refer to "Which Rules Event should I use to change the value of a Select List field?" for more details what this example is about):

{ "rules_force_a_value_for_past_due_dates" : {
    "LABEL" : "Force a value for past due dates",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_presave" : [] },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_expiration_date" } },
      { "data_is" : {
          "data" : [ "node:field-expiration-date" ],
          "op" : "\u003C",
          "value" : [ "site:current-date" ]
        }
      },
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_optionlist" } }
    ],
    "DO" : [
      { "data_set" : { "data" : [ "node:field-optionlist" ], "value" : "A" } }
    ]
  }
}

Without the first entity_has_field-condition (about field_expiration_date), it would be impossible to select that field as a token in the 2nd Rules Condition (it simply wouldn't be shown in the select list to select a token).

Without the second entity_has_field-condition (about field_optionlist), it would be impossible to select that field as a token in the Rules Action (again, it simply wouldn't be shown in the select list to select a token).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.