I followed the instructions included in the answer to the question "How to implement the mass operations on the Group's members page using Views?". The 2 Rules Components in it (to either block or unblock a member), work fine (and my VBO view shows the mass operations that use those 2 Rules Components).

Now I want to create a similar Rules Component for one of the other typical mass update operations (as used in the context of the Group module).

Below is the Rules Components (in Rules export format) I created for this so far, to "Delete selected members":

{ "rules_remove_a_group_membership" : {
    "LABEL" : "Remove a group membership",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "USES VARIABLES" : { "group_mbrship" : { "label" : "Group membership", "type" : "group_membership" } },
    "DO" : []

This Rules Component should implement the equivalent of the Update option "Remove selected members" (as shown on group/gid/member, with gid=group id).

My question:

Something seems wrong in the Rule Component shown above, since I can't get it to do the equivalent of the Update option of the Group module (using VBO, similar to the answer in the question I mentioned above).

So how to correct this Rules Component to perform the equivalent operation using a custom VBO action created using a Rules Component, so that with the addition of this component, my custom VBO page should be equivalent to the default page of 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.


| improve this answer | |
  • Thank you for this answer. But I also get an error ajax 500. The member page displays "The website encountered an unexpected error, please try again later." I had already tested this solution but it does not work. – user54067 Nov 19 '16 at 11:16
  • I updated my question to "2. Add a role to the selected members" but I also encountered an error AJAX 500. – user54067 Nov 19 '16 at 11:26
  • About your 1st comment: do you ALSO get that ajax error if you (a) DISABLE your Rules Component for bullet "1." in your VBO field AND ENABLE the standard VBO action "delete item" (as in part 3 of my answer)? FYI: with that combination I do not get any (AJAX) error, and the selected membership row(s) are perfectly deleted via VBO. Let me know, OK? PS: if you have any custom Rules Component in your VBO view enabled for bullet 2 or 3, then also disable those (for now), to see if the AJAX error is gone (it should). – Pierre.Vriens Nov 19 '16 at 11:31
  • Yes it works. Should it leave the component? – user54067 Nov 19 '16 at 11:40
  • @Mathieu ... EURECA (the AJAX error is resolved). With that I'd done with the answer for Bullet 1 in your question ... – Pierre.Vriens Nov 19 '16 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy