0

I have an ECK entity (not a node) in Drupal 7 that contains both properties and fields. Some fields are single value fields e.g. field_tags and others are multi-value fields e.g. field_description with a maximum of 3 fields (rows or textareas).

I want to use Rules to check if a field has been updated after saving the ECK entity in order to set some specific settings, if they were updated. I have tried to create a test rule first to see how this works and it works but only for some single value fields like field_tags but not other single-value fields like field_image AND not for the multi-value fields like field_description (which has 3 textareas (3 rows)).

I understand that I have to check first "entity has field" to get both the changed and the unchanged values of that entity before I can use them in a conditional.

So for the field_tags it works. For the field_image, field_video_reference, etc it doesn't work. And for the multi-value fields, I simply don't know how to compare these values. I thought: field_description:0 but that doesn't seem to work either.

Below is what I've got so far. If I update one of the entities (of type Course) I only get a message (and this message is correct) if the tags (field_tags) are changed. If I change anything else, there is no message. Why? I have no idea.

And like I mentioned, multi-value fields don't work and I have no idea how to compare them.
What do you think I'm doing incorrectly or what have I missed?

Here's my rule with the integrated Component Rule to check:

{ "rules_test_rule_to_check_if_course_values_have_been_changed2" : {
"LABEL" : "Test rule to check if Course values have been changed2",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "eck" ],
"ON" : { "course_update" : [] },
"DO" : [
  { "component_rules_test_rule_to_check_if_course_tags_have_been_changed3" : {
      "the_course" : [ "course" ],
      "the_unchanged_course" : [ "course-unchanged" ]
    }
  }
]}}

Here's my Component Rule:

{ "rules_component_if_specific_course_values_have_changed" : {
"LABEL" : "Check and set moderation status if specific Course values have changed",
"PLUGIN" : "rule",
"OWNER" : "rules",
"TAGS" : [ "changed", "course", "moderation status", "specific values" ],
"REQUIRES" : [ "rules", "rules_conditional" ],
"USES VARIABLES" : {
  "the_course" : { "label" : "The Course", "type" : "course" },
  "the_unchanged_course" : { "label" : "The Unchanged Course", "type" : "course" }
},
"IF" : [
  { "entity_has_field" : { "entity" : [ "the-course" ], "field" : "field_tags" } },
  { "entity_has_field" : { "entity" : [ "the-unchanged-course" ], "field" : "field_tags" } },
  { "entity_has_field" : {
      "entity" : [ "the-course" ],
      "field" : "field_single_session_course_ref"
    }
  },
  { "entity_has_field" : {
      "entity" : [ "the-unchanged-course" ],
      "field" : "field_single_session_course_ref"
    }
  },
  { "entity_has_field" : { "entity" : [ "the-course" ], "field" : "field_category" } },
  { "entity_has_field" : { "entity" : [ "the-unchanged-course" ], "field" : "field_category" } },
  { "entity_has_field" : { "entity" : [ "the-course" ], "field" : "field_video_reference" } },
  { "entity_has_field" : {
      "entity" : [ "the-unchanged-course" ],
      "field" : "field_video_reference"
    }
  },
  { "entity_has_field" : { "entity" : [ "the-course" ], "field" : "field_image" } },
  { "entity_has_field" : { "entity" : [ "the-unchanged-course" ], "field" : "field_image" } },
  { "entity_has_field" : { "entity" : [ "the-course" ], "field" : "field_layout_img1" } },
  { "entity_has_field" : { "entity" : [ "the-unchanged-course" ], "field" : "field_layout_img1" } }
],
"DO" : [
  { "CONDITIONAL" : [
      {
        "IF" : { "data_is" : {
            "data" : [ "the-course:field-tags" ],
            "value" : [ "the-unchanged-course:field-tags" ]
          }
        },
        "DO" : [
          { "drupal_message" : { "message" : "Field tags were the SAME " } }
        ]
      },
      { "ELSE" : [
          { "drupal_message" : { "message" : "Field tags were NOT THE SAME" } }
        ]
      }
    ]
  },
  { "CONDITIONAL" : [
      {
        "IF" : { "data_is" : {
            "data" : [ "the-course:field-single-session-course-ref" ],
            "value" : [ "the-unchanged-course:field-single-session-course-ref" ]
          }
        },
        "DO" : [
          { "drupal_message" : { "message" : "Field Single Session Course Ref was the SAME " } }
        ]
      },
      { "ELSE" : [
          { "drupal_message" : { "message" : "Field Single Session Course Ref was NOT THE SAME" } }
        ]
      }
    ]
  },
  { "CONDITIONAL" : [
      {
        "IF" : { "data_is" : {
            "data" : [ "the-course:field-video-reference" ],
            "value" : [ "the-unchanged-course:field-video-reference" ]
          }
        },
        "DO" : [
          { "drupal_message" : { "message" : "Field Video Ref was the SAME " } }
        ]
      },
      { "ELSE" : [
          { "drupal_message" : { "message" : "Field Video Ref was NOT THE SAME" } }
        ]
      }
    ]
  },
  { "CONDITIONAL" : [
      {
        "IF" : { "data_is" : {
            "data" : [ "the-course:field-image" ],
            "value" : [ "the-unchanged-course:field-image" ]
          }
        },
        "DO" : [
          { "drupal_message" : { "message" : "Field image was the SAME " } }
        ]
      },
      { "ELSE" : [
          { "drupal_message" : { "message" : "Field image was NOT THE SAME" } }
        ]
      }
    ]
  },
  { "CONDITIONAL" : [
      {
        "IF" : { "data_is" : {
            "data" : [ "the-course:field-layout-img1" ],
            "value" : [ "the-unchanged-course:field-layout-img1" ]
          }
        },
        "DO" : [
          { "drupal_message" : { "message" : "Field Layout Image was the SAME " } }
        ]
      },
      { "ELSE" : [
          { "drupal_message" : { "message" : "Field Layout Image was NOT THE SAME" } }
        ]
      }
    ]
  }
]}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.