I created a variation of the Rules Component in comment nr 5 of issue #2603136: Rules integration. Here is how my Rules Component looks like:

{ "rules_add_role_to_selected_group_members" : {
    "LABEL" : "Add role to selected group members",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ACCESS_EXPOSED" : "1",
    "USES VARIABLES" : {
      "parm_group_mbrship" : { "label" : "Parm Group Membership", "type" : "group_membership" },
      "parm_group_role" : { "label" : "Parm Group Role machine name", "type" : "group_role" }
    },
    "IF" : [
      { "NOT list_contains" : {
          "list" : [ "parm-group-mbrship:roles" ],
          "item" : [ "parm-group-role" ]
        }
      }
    ],
    "DO" : [
      { "drupal_message" : { "message" : "Role data passed as parm:\u003Cbr \/\u003E\r\n\u003Cbr \/\u003E\r\nparm-group-role:rid = [parm-group-role:rid]\u003Cbr \/\u003E\r\nparm-group-role:group-type=[parm-group-role:group-type]\u003Cbr \/\u003E\r\nparm-group-role:label=[parm-group-role:label]\u003Cbr \/\u003E\r\n\u003Cbr \/\u003E" } },
      { "entity_fetch" : {
          "USING" : { "type" : "group_membership", "id" : [ "parm-group-mbrship:mid" ] },
          "PROVIDE" : { "entity_fetched" : { "membership_fetched" : "Fetched Membership" } }
        }
      },
      { "drupal_message" : { "message" : "Fetched membership data:\u003Cbr \/\u003E\r\n\u003Cbr \/\u003E\r\nmembership-fetched:mid = [membership-fetched:mid]\u003Cbr \/\u003E\r\nmembership-fetched:group=[membership-fetched:group]\u003Cbr \/\u003E\r\nmembership-fetched:roles=[membership-fetched:roles]\u003Cbr \/\u003E\r\n\u003Cbr \/\u003E" } },
      { "list_add" : {
          "list" : [ "membership-fetched:roles" ],
          "item" : [ "parm-group-role" ],
          "unique" : "1"
        }
      },
      { "entity_save" : { "data" : [ "membership-fetched" ], "immediate" : "1" } }
    ]
  }
}

To QA-test my Rules Component, I execute it from within the Rule UI, using its "execute" link to the right of the Rules Component, and I enter these arguments for it:

  • For 'Parm Group Membership' I use 'Group membership identifier' = 7 (entered after switch to direct input mode)
  • For 'Parm Group Role machine name' I use 'Group role identifier' = instructor

The "Display a message" actions are to facilitate debugging for now. Here is how a sample of them (when executing the Rules Component) looks like:

Role data passed as parm:

parm-group-role:rid = 3
parm-group-role:group-type=Class
parm-group-role:label=Instructor

Fetched membership data:

membership-fetched:mid = 7
membership-fetched:group=Drupal for Sitebuilders
membership-fetched:roles=Class: Student

However I run into an error which looks like so:

Recoverable fatal error: Object of class GroupRole could not be converted to string in GroupMembershipController->save() (line 141 of .../sites/all/modules/group/classes/group_membership.controller.inc).

To take this a step further, I also tried to execute this Rules Component using the "role id" of "3" (for the same "instructor" role), specified as parm for "parm_group_role". However in that case my "Display a message"-actions don't display anything at all. And instead I get these errors that show up if I enable Rules debugging:

0 ms Executing action rule: Add role to selected group members.
33.275 ms Unable to get a data value. Error: Invalid data value given. Be sure it matches the required data type and format. Value at group_role(): 3.
33.795 ms Unable to evaluate action component_rules_add_role_to_selected_group_members.

My questions:

  1. How to resolve that GroupMembershipController-error?
  2. What should I specify as the value for the "Group role identifier": instructor, 3, or yet something else?
  3. How can I get my Rules Component to do what I want it to do, ie add a role for the Group Membership specified as a Parameter for my Rules Component?

Comments

Pierre.Vriens created an issue. See original summary.

Pierre.Vriens’s picture

Issue summary: View changes
Pierre.Vriens’s picture

Title: How to resolve my GroupMembershipController-error in my Rules Component? » How to resolve the GroupMembershipController-error in my Rules Component?
Pierre.Vriens’s picture

Issue summary: View changes
Pierre.Vriens’s picture

Sorry to ask, and I realize Lots of effort is put in D8, but is the D7 version of Group still "supported"? Ie does it still make sense to post "support requests" about D7?

soul88’s picture

Status: Active » Closed (outdated)

We thank everyone for their collaboration on this issue, but as the D7 version is no longer supported, we will now close all D7 issues to keep the issue queue a bit tidier. This information won't go anywhere, it just won't show up on the list of open issues anymore.

Please see: https://www.drupal.org/project/group/issues/3163655 and https://www.drupal.org/project/group/issues/3203863#comment-14100281 for more details.