0

I am using a content type called "question" which has an organic group reference field (og_group_ref).

I want to trigger an action with Rules, when the field "og_group_ref" is changed on node update.

So I have created the following rule:

{ "rules_notify_question_author" : {
"LABEL" : "Question has moved - notify user",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"ON" : { "node_update--question" : { "bundle" : "question" } },
"IF" : [
  { "AND" : [
      { "NOT data_is" : {
          "data" : [ "node-unchanged:og-group-ref" ],
          "value" : [ "node:og-group-ref" ]
        }
      }
    ]
  },
  { "NOT data_is_empty" : { "data" : [ "node:og-group-ref" ] } }
],
"DO" : [
  { "mail" : {
      "to" : "[node:author:mail]",
      "subject" : "Some handy subject",
      "message" : "E-Mail to author",
      "from" : "[site:mail]",
      "language" : [ "" ]
    }
  },
  { "drupal_message" : { "message" : "Message text" } } } }
]

The idea is that the author of a question gets notified, when the questions was moved to another group. The logic should be like this:

EVENT: On Node question Update

CONDITION: node_unchanged:og-group-ref != node:og-group-ref AND node:og-group-ref != EMPTY

ACTION: Send Mail an show a message

My problem is, that the rule fires when the content of the field og_group_ref was changed and when it was NOT changed.

I printed the compared values in the drupal message. The values are correct. But I do not know, why the rule is triggered although the field "og_group_ref" did not change.

Has anyone an idea?

1
  • The problem seems to be, that the compared datas are objects and these are always different. If i compare the field og_group_ref:0:nid rules returns arrays with different indices so you can not compare the values. I will create my own rule programmatically
    – sgoelz
    Commented Dec 12, 2014 at 8:41

1 Answer 1

0

I solved the problem by creating an own condition for rules using the API of the rules module.

function hook_rules_condition_info() {
  return array(
    'rules_condition_text_compare' => array(
      'label' => t('Textual comparison'), 
      'parameter' => array(
        'text1' => array(
          'label' => t('Text 1'),
          'type' => 'text',
        ), 
        'text2' => array(
          'label' => t('Text 2'),
          'type' => 'text',
        ),
      ), 
      'group' => t('Rules'),
    ),
  );
}

See hook_rules_condition_info for more details.

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.