It doesn't seem like Rules is able to retrieve data through field collections...

Here's my scenario:

  • I'm using Entityforms to create a form that contains several Field collection fields.
  • Each Field collection field is multi-valued.
  • I'm using Entityforms support for Rules to validate form submissions.
  • In the validation rules, I need to check the value of a field inside the first two Field collection items of a field.

Here's the structure:

  • Application Form
    • field_people [0..N]
      • field_person_type [1]

So, basically, the rule is trying to look at the values of field_people[0][field_person_type] and field_people[1][field_person_type].

Here's a simple copy of my validation rule (just checks to see whether field_people[0] even exists):

{ "rules_test" : {
    "LABEL" : "Test",
    "PLUGIN" : "rule",
    "TAGS" : [ "entityform validation" ],
    "REQUIRES" : [ "rules" ],
      "entityform" : { "label" : "Submitted Entityform", "type" : "entityform" },
      "entityform_type" : { "label" : "Entityform Type", "type" : "entityform_type" },
      "validate_form" : { "label" : "Form Validates", "type" : "boolean", "parameter" : false }
    "IF" : [
      { "entity_has_field" : { "entity" : [ "entityform" ], "field" : "field_people" } },
      { "NOT data_is_empty" : { "data" : [ "entityform:field_people:0" ] } }
    "DO" : [ { "drupal_message" : { "message" : "REBOOT... ALL THE THINGS!" } } ],
    "PROVIDES VARIABLES" : [ "validate_form" ]

Here's a sample of the data in the form:

->field_people = array(
0 => array(
'field_person_type' => array(
0 => array(
'value' => 'mother',

Here's the rules execution output:

Rules debug information:
" Executing rule Test.
0 ms Executing rule Test.
4.591 ms Evaluating conditions of rule Test. [edit]
5.533 ms The condition entity_has_field evaluated to TRUE [edit]
7.166 ms The condition data_is_empty evaluated to TRUE [edit]
7.178 ms AND evaluated to FALSE.
7.394 ms Finished executing of rule Test.

This seems like a bug... am I doing something wrong?


GuyPaddock’s picture

Hmm, this is definitely an issue in Field Collection.

I noticed that when I use nodes instead of Entityforms, I don't experience the same behavior. It seems that there is some sort of problem with field_collection_field_property_get() for non-node types. Basically, stepping through the code, it looks like the 'value' key of each delta isn't set at the time that method is invoked for non-nodes.

For node types, hook_field_presave() gets invoked beforehand, allowing the 'value' key to be fully populated before field_collection_field_property_get() is invoked. For the Entityform types, it looks like that same logic only runs after the call to field_collection_field_property_get().


GuyPaddock’s picture

Category:support» bug

This is definitely a bug in field_collection. Apparently, FC can't handle dealing with FC item data before the entity presave hook has been invoked, which is exactly what happens when rules code is invoked on an entity during a form_validate.

It looks like something will need to change in field_collection_field_property_get to address this...

GuyPaddock’s picture

Issue summary:View changes

Added structure of the entity form data.