0

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.

4
  • 1
    Am I right in assuming that you can (also) create a view of ALL (not more, not less) "previous submissions to be deleted? Also, can you improve your question by including an export of the Rules component(s) for which you wrote "The components work". 1 more question: any links to those "few older issues"? Commented Mar 5, 2017 at 20:59
  • Updates added. And yes, I can create a view of ALL. I'll have to go hunting for the links. Will post them here if I can locate them again.
    – tonka69
    Commented Mar 5, 2017 at 21:20
  • For using Rules: Fetch by Property, you would use the author property and current user uid I guess. Or for the VBO view, you need a contextual filter for entityform author that takes default: URL argument: 2 (I think), and in your rule, send the current user uid in the rule action for VBO. I can look at this properly tomorrow. Commented Mar 6, 2017 at 16:56
  • That helps. I'm nearly there - added a compare userID variable to the rule component and placed that instead of the VBO in the Fetch series. It's still looking to match the user against the entity-fetch:0, though, and if there's no match, it doesn't work. I need to figure out how to get it to look only at the first item in the USER set.
    – tonka69
    Commented Mar 7, 2017 at 3:18

1 Answer 1

0

Got this to work in rules by creating a rule set, which relates the variables and actions to each other instead of processing them separately. Still haven't figured out how to delete entityform submissions via Views, but at this point, it's academic.

If anyone is interested, this is the code that worked:

{ "rules_current_project_fetch_by_uid_rule_2" : { "LABEL" : "Current Project Fetch by UID Rule 2", "PLUGIN" : "reaction rule", "OWNER" : "rules", "REQUIRES" : [ "rules", "entityform" ], "ON" : { "entityform_presave" : [] }, "IF" : [ { "data_is" : { "data" : [ "entityform:type" ], "value" : "myplatform_current_project" } }, { "AND" : [] }, { "entity_is_of_type" : { "entity" : [ "entityform" ], "type" : "entityform" } } ], "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" : "Current list item" }, "DO" : [ { "component_rules_current_project_fetch_by_uid_component" : { "current_project_submission" : [ "list-item" ] } } ] } } ] } }

The rule set looks like this:

{ "rules_current_project_fetch_by_uid_component" : { "LABEL" : "Current Project Fetch by UID component", "PLUGIN" : "rule set", "OWNER" : "rules", "REQUIRES" : [ "rules" ], "USES VARIABLES" : { "current_project_submission" : { "label" : "Current Project Submission", "type" : "entityform" } }, "RULES" : [ { "RULE" : { "PROVIDE" : { "variable_added" : { "variable_added_type" : "Added variable", "variable_added_submission" : "Added variable" } }, "IF" : [ { "data_is" : { "data" : [ "current-project-submission:type" ], "value" : "myplatform_current_project" } }, { "AND" : [] }, { "entity_is_of_type" : { "entity" : [ "current-project-submission" ], "type" : "entityform" } }, { "AND" : [] }, { "data_is" : { "data" : [ "current-project-submission:user" ], "value" : [ "site:current-user" ] } } ], "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" : [ "current-project-submission" ] }, "PROVIDE" : { "variable_added" : { "variable_added_submission" : "Added variable" } } } } ], "LABEL" : "Current Project UID Variables" } }, { "RULE" : { "IF" : [ { "data_is" : { "data" : [ "variable-added-type" ], "value" : "myplatform_current_project" } }, { "data_is" : { "data" : [ "variable-added-submission" ], "value" : [ "current-project-submission" ] } }, { "data_is" : { "data" : [ "current-project-submission:uid" ], "value" : [ "site:current-user:uid" ] } } ], "DO" : [ { "entity_delete" : { "data" : [ "current-project-submission" ] } } ], "LABEL" : "Current Project UID Delete" } } ] } }

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.