1

I use the Group module and the "Ginvite" submodule on Drupal 7.52.

The module allows you to invite people (either registered users or users without an account) to become a member of the group that the invitation is about.

enter image description here

This is what happens after somebody is invited:

  • When I write an email in "Invitations by email" and the person is not registered on my site, then the person receives an email invitation.
  • when I write an email in "Invitations by email" and the person is already registered on my site, then the person receives an invitation message on the user's account, as shown in this screenprint:

    enter image description here

However, I want people who already have a user account, to receive an email notification about that invitation in addition to the invitation (message) on their user account.

How to do this?

  • @Pierre.Vriens I have updated my question. I do not know what to put more. – user54067 Nov 25 '16 at 14:22
  • Now the question is clear, and complete ... I think! – Pierre.Vriens Nov 25 '16 at 14:27
1

You can use the Rules module to achieve that "people who already have a user account, also receive an email invitation in addition to the invitation on their user account" (as in your question).

Here is the rule (in Rules export format) to actually do so:

{ "rules_send_email_after_inviting_a_registered_user" : {
    "LABEL" : "Send eMail after inviting a registered user",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "group" ],
    "ON" : { "group_membership_insert" : [] },
    "IF" : [
      { "data_is" : { "data" : [ "group-membership:status" ], "value" : "invited" } },
      { "NOT user_has_role" : {
          "account" : [ "group-membership:user" ],
          "roles" : { "value" : { "1" : "1" } }
        }
      }
    ],
    "DO" : [
      { "mail" : {
          "to" : "[group-membership:user:mail]",
          "subject" : "You have a pending group invitation",
          "message" : "Hi there!\r\n\r\n[site:current-user:name] has invited you to become a member of the group \u0022[group-membership:group]\u0022 on [site:name].\r\nIf you wish to accept the invitation, you need to login with your existing account first, which is \u0022[group-membership:user:name]\u0022.\r\nPlease visit the following address in order to do so: [site:login-url]\r\n\r\nKind regards,\r\nThe [site:name] team",
          "from" : "[site:current-user:mail]",
          "language" : [ "" ]
        }
      },
      { "drupal_message" : { "message" : "You just invited existing user with name [group-membership:user:name] and eMail Id [group-membership:user:mail] to the group named [group-membership:group].\r\n\r\nAn appropriate message about this invitation just got eMailed to [group-membership:user:name] also." } }
    ]
  }
}

Some more details about the magic included in this rule:

  • Sending an invitation in the Group module's terminology is equivalent to inserting a new Group Membership with status "invited" (how easy can it be?). So that explains the Rules Event I'm using, and the first Rules Condition.
  • Since we only want to send such eMail to users who already have an account, the 2nd Rules Condition is to check that the invited user does NOT (!!!) have role anonymous.
  • The Rules Action is just to send an appropriate eMail, using specific tokens related to the Group Membership, etc.
  • For debugging purposes, the 2nd Rules Action shows a confirmation message about the triggered eMail (feel free to remove that action if you don't like it).

Just import the above rule (using the Rules UI) in your own site, with no customization (changes) needed to see it at work in your own site (don't worry, there is no spyware in the eMail being produced ...).

The eMail content is pretty close to the eMail delivered when inviting anonymous users (the only difference is that it has an instruction to login with their existing account, also included in the eMail body). Here is how a sample eMail body looks like:

Hi there!

Pierre.Vriens has invited you to become a member of the group
"Drupal for Sitebuilders" on www.example.com.

If you wish to accept the invitation, you need to login with your existing
account first, which is "Dries.Buytaert".

Please visit the following address in order to do so:
http://www.example.com/user

Kind regards,
The www.example.com team

Possibly you may want to finetune the eMail subject, or eMail body. But apart from that no other changes should be needed.

Voilà ...

  • @Mathieu, merci! May I say "What else did you expect"??? Not sure if you realize, but this could be used as a prototype also for anything to implement "tracking" of who invites who, and if an invite is accepted, then make another something happen for the inviting user, such as granting user points, assiging user badges, combining it with the Goals module (eg: to identify / reward users who succeed in inviting X other users). If any of these thoughts make you wonder how to do so, use this link – Pierre.Vriens Nov 26 '16 at 9:20
  • 1
    thank you for all those informations. Indeed this rule offers many possibilities – user54067 Nov 26 '16 at 9:51

Your Answer

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