0

The setup

I have an entity (ECK) that has a boolean property (not a field).
In that same entity I have a regular text field property.
I have a rule that contains a conditional in the action section.
The conditional is evaluating a component that evaluates certain settings of that entity.
This all works fine.

The problem.

I'm trying to add a condition set (rule) to my (AND) component because I need to check the following:
If the text field property has content, then the boolean property should be ticked.
If the text field property doesn't have content, then the boolean property should be unticked.

The result of the above should be: TRUE
so that this is my 5th (AND) condition in my (AND) component

My (AND) component contains 2 parameters:

  1. Course: the entity
  2. A truth value: my_specific_tc_agreement

My condition set (rule) contains 2 parameters:

  1. Course: the entity
  2. A truth value: specific_tc_agreement

The (AND) Condition

{ "rules_criteria_to_check_before_completing_a_course_booking" : {
"LABEL" : "Criteria to check before completing a Course booking",
"PLUGIN" : "and",
"OWNER" : "rules",
"TAGS" : [ "book", "booking", "Course", "Course entity", "entity", "Student" ],
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : {
  "course_to_check" : { "label" : "The Course to check", "type" : "course" },
  "my_specific_tc_agreement" : { "label" : "My Specific TC Agreement", "type" : "boolean" }
},
"AND" : [
  { "NOT data_is_empty" : { "data" : [ "course-to-check:student-name" ] } },
  { "NOT data_is_empty" : { "data" : [ "course-to-check:the-why" ] } },
  { "entity_has_field" : {
      "entity" : [ "course-to-check" ],
      "field" : "field_accepted_commitments"
    }
  },
  { "data_is" : {
      "data" : [ "course-to-check:your-commitment" ],
      "op" : "IN",
      "value" : [ "course-to-check:field-accepted-commitments" ]
    }
  },
  { "data_is" : { "data" : [ "course-to-check:t-c-agreement" ], "value" : "1" } }
] } }

The Condition Set

{ "rules_course_specific_t_c_check" : {
"LABEL" : "Course Specific T\u0026C Check",
"PLUGIN" : "rule condition set",
"OWNER" : "rules",
"TAGS" : [ "Check", "Course", "specific agreement", "T\u0026C" ],
"REQUIRES" : [ "rules_conditional", "rules", "devel" ],
"USES VARIABLES" : {
  "the_course" : { "label" : "The Course", "type" : "course" },
  "specific_tc_agreement" : { "label" : "specific TC agreement", "type" : "boolean" }
},
"DO" : [
  { "variable_add" : {
      "USING" : { "type" : "boolean" },
      "PROVIDE" : { "variable_added" : { "my_truth_value" : "My Truth Value" } }
    }
  },
  { "CONDITIONAL" : [
      {
        "IF" : { "data_is_empty" : { "data" : [ "the-course:course-specific-t-c-content" ] } },
        "DO" : [ { "data_set" : { "data" : [ "my-truth-value" ], "value" : "0" } } ]
      },
      { "ELSE" : [ { "data_set" : { "data" : [ "my-truth-value" ], "value" : "1" } } ] }
    ]
  },
  { "devel_debug" : { "value" : [ "my-truth-value" ] } }
],
"RESULT" : [
  { "data_is" : { "data" : [ "my-truth-value" ], "value" : [ "specific-tc-agreement" ] } }
] } }

The Final Rule

{ "rules_test_rule_user_updates_course" : {
"LABEL" : "Test Rule User Updates Course",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules_conditional", "rules", "eck" ],
"ON" : { "course_update" : [] },
"DO" : [
  { "CONDITIONAL" : [
      {
        "IF" : { "component_rules_criteria_to_check_before_completing_a_course_booking" : { "course_to_check" : [ "course" ], "my_specific_tc_agreement" : "1" } },
        "DO" : [ { "drupal_message" : { "message" : "This resulted in TRUE" } } ]
      }
    ]
  }
] } }

When I try to add this condition set into my (AND) component, it asks me for the specific-tc-agreement but that's not available. The only other option that I have is to set it to true or false but that's not what I need. What I need is to compare the specific-tc-agreement from that entity (Course) with my truth value from the condition set.

How do I make this boolean property available in my rule and component? Adding a condition "Entity has field" doesn't work because it's not a field, it's a property. Adding a condition "Data value is empty" doesn't work either because it can be empty and it can be set.

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.