I'm trying to set a reaction rule that checks for previous submissions from a user and deletes them when new form data is submitted.
I had success getting the fields to delete using the Fetch action, but I only want to pull submissions from the current user, and I haven't quite figured out the right component rule set to make this work yet.
Whenever I introduce VBO to the equation, the rule stops deleting. The components work. The VBO works on itself. They just don't play nice together. I've tried every possible configuration under the sun (I think), but so far nothing works.
I've read a few older issues that suggest that VBO cannot be used to delete entityform submissions. Most of the replies that say you can actually address nodes, but don't work for entityforms specifically.
So, my question is: can I delete entityform submissions via VBO in rules? If not, should I be looking to do this programmatically instead, or is there another workaround?
For example: I can execute a basic entity-delete component like this:
{ "rules_delete_current_project" : {
"LABEL" : "Delete Old Current Project",
"PLUGIN" : "rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : { "current_project" : { "label" : "Current Project", "type" : "list\u003Centityform\u003E" } },
"IF" : [
{ "data_is" : {
"data" : [ "current-project:0:type" ],
"value" : "myplatform_current_project"
}
}
],
"DO" : [ { "entity_delete" : { "data" : [ "current-project:0" ] } } ]
}
}
Meanwhile, the following reaction rule with Fetch action deletes the last Entityform Submission, but won't respond to restrictions forcing it to address only current user content:
{ "rules_delete_existing_current_project" : {
"LABEL" : "Delete Existing Current Project",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "entityform" ],
"ON" : { "entityform_insert" : [] },
"IF" : [
{ "data_is" : {
"data" : [ "entityform:type" ],
"value" : "myplatform_current_project"
}
},
{ "AND" : [
{ "entity_is_of_type" : { "entity" : [ "entityform" ], "type" : "entityform" } }
]
},
{ "AND" : [
{ "data_is" : { "data" : [ "entityform:uid" ], "value" : [ "site:current-user:uid" ] } }
]
}
],
"DO" : [
{ "entity_query" : {
"USING" : {
"type" : "entityform",
"property" : "type",
"value" : [ "entityform:type" ]
},
"PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
}
},
{ "LOOP" : {
"USING" : { "list" : [ "entity-fetched" ] },
"ITEM" : { "list_item_parameters" : "Current list item" },
"DO" : [
{ "variable_add" : {
"USING" : { "type" : "entityform_type", "value" : "myplatform_current_project" },
"PROVIDE" : { "variable_added" : { "variable_added_type" : "Added variable" } }
}
},
{ "variable_add" : {
"USING" : { "type" : "entityform", "value" : [ "entity-fetched:0" ] },
"PROVIDE" : { "variable_added" : { "variable_added_submission" : "Added variable" } }
}
},
{ "variable_add" : {
"USING" : { "type" : "user", "value" : [ "entity-fetched:0:user" ] },
"PROVIDE" : { "variable_added" : { "variable_added_user" : "Added variable" } }
}
}
]
}
},
{ "LOOP" : {
"USING" : { "list" : [ "entity-fetched" ] },
"ITEM" : { "list_item" : "Current list item" },
"DO" : [
{ "component_rules_vbo_current_project_select" : {
"current_project_list" : [ "entity-fetched" ],
"user" : [ "list-item:user" ]
}
},
{ "entity_delete" : { "data" : [ "entity-fetched:0" ] } }
]
}
}
]
}
}
This is one of the few reaction rule combinations I could get to work cleanly with the VBO and referencing the component above. It does not delete.
{ "rules_another_rules_test" : {
"LABEL" : "Another rules test",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "views_bulk_operations", "entityform" ],
"ON" : { "entityform_insert" : [] },
"IF" : [
{ "data_is" : { "data" : [ "entityform:type" ], "value" : "myplatform" } }
],
"DO" : [
{ "views_bulk_operations_action_load_list" : {
"USING" : { "view" : "backend_current_project_edit|default" },
"PROVIDE" : { "entity_list" : { "entity_list" : "A list of entities" } }
}
},
{ "LOOP" : {
"USING" : { "list" : [ "entity-list" ] },
"ITEM" : { "list_item" : "Current list item" },
"DO" : [
{ "component_rules_delete_current_project" : { "current_project" : [ "entity-list" ] } }
]
}
}
]
}
}
The view which works on its own is structured:
Format:
Unformatted list | Settings
Show:Fields | Settings
Fields:
Entityform Submission: Entityform submission ID
Entityform Submission: Current Project
Entityform Submission: Select Project
Bulk operations: Entityform Submission
Filter criteria:
Entityform Submission: Entityform Type (= MyPlatform Current Project)
Entityform Submission: Uid (reference filter)
I have Bulk Operations set to:
Y Delete Current Project
Y Skip confirmation step
Y Skip permission step
Y Override label
I've been coding this in circles for a while, so the variable names might not match from one region to the next.