How to correct my Rules Component to perform VBO operations for the Group module?
Part 1: Create a Rules Component

Have a look at this Rules Component (in Rules export format):

{ "rules_remove_selected_group_members" : {
    "LABEL" : "Remove selected group members",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "group_mbrship" : { "label" : "Group membership", "type" : "group_membership" } },
    "DO" : [ { "entity_delete" : { "data" : [ "group-mbrship" ] } } ]
  }
}


Some more details to further explain the above Rules Component:


It uses a "Group membership" (which is an entity, remember!) as a parameter.
All it does is to perform an Action "Delete entity", for the entity specified as parameter.


By deleting such entity, you do the same as what happens when using the "Remove selected members" (for 1 specific Group membership, entered as parameter).

If you want, just copy the exported Rules Component above, and import it in your own environment. Then navigate to admin/config/workflow/rules/components in your own site and use the hyperlink "execute" to qa-test it in your own site. After you use that link, use the button that says Switch to direct input mode. Then you'll be able to enter some Group membership identifier and hit the Execute button. The Group membership for the id you specified will be deleted then.

Tip: (temporary) improve your Group Membership view to also include the field "Group Membership Id" (=mid). This makes it easy to know which ID to use when testing this Rules Component.

After you're confident this Rules Component works perfect for all variations of your nodes, it's time to move on to Part 2 below.

Part 2: Extend your VBO view

The typical next step when creating custom VBO oprations, is to edit the VBO field in your view, and enable the additional VBO operation that corresponds to the Rules Component as in Part 1.

In my case, with the VBO view I'm using, I ran into some AJAX error which I could not resolve right away. I was pretty sure it is NOT a bug, but rather something I'm doing wrong. Head over to Part 4 for more details on that.

However while further investigating this error, I realized that there is no need at all for a Rules Component to implement that VBO action "Remove selected members". Head over to Part 3 for more details on that (sometimes the solution to a problem, is to prevent the problem from happening ...).

Part 3: Enable a standard VBO action

Head back to your VBO field in your view, and enable "Delete item" (within Selected Bulk Operations). I suggest to use the "Override label"-option for it, and give that VBO action a label like "Remove selected members".

QA-test this VBO action to confirm it does exactly the same as:


what you try to achieve with the custom Rules Component in bullet 1 of your question.
what I try to achieve with my Rules Component in Part 1 of this answer.


Part 4: Heading for the golden cradle (= Solve the AJAX error)

The AJAX error as in Part 2 is resolved by using this variation of the Rules Component from Part 1:

{ "rules_remove_selected_group_members" : {
    "LABEL" : "Remove selected group members",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ACCESS_EXPOSED" : "1",
    "USES VARIABLES" : { "group_mbrship" : { "label" : "Group membership", "type" : "group_membership" } },
    "DO" : [
      { "entity_delete" : { "data" : [ "group-mbrship" ] } },
      { "drupal_message" : { "message" : "Membership of group [group-mbrship:group:title] removed for user [group-mbrship:user]." } }
    ]
  }
}


Note the "ACCESS_EXPOSED" : "1" added here now (apart from the extra "drupal_message" Action, which has nothing to do with the AJAX error). That turns out to be the clue to solve the AJAX error. For (way) more details on this, refer to Comment nr 13 in Support issue # 2530000. My understanding about that comment is that something in Entity API or Rules is what causes the AJAX error, and by using this access setting you prevent the issue.

With that, you now have 2 solutions/answers to solve your question ... i.e. to Remove selected members. My preference is using the Rules Component from Part 4, because:


The messages you get after executing it are more detailed as compared to Part 3.
If you want, you can add any additional Rules Action or Rules Condition in the Rules Component.


Voilà!