How to create a message with message stack when user becomes a member of a group module group? Hi currently I try to code a custom module for notification based on message stack module.
Now I'm searching for the event or hook to perform some custom code when the user becomes a member of a group.
I want to create a message based on the message stack like &quot;the user John Doe became a member of group xxx. Visit group xxx.&quot;
Unfortunately I didn't found something like that in the module docs, so I ask here.
Thanks in advance for your help
It looks like the membership relationship is stored as a GroupContent entity, so in theory you would use something like hook_ENTITY_TYPE_insert()as your event:
function MODULE_group_content_insert(\Drupal\group\Entity\GroupContentInterface $group_content) {
  // This will fire for all types of group content so make sure to filter
  if ($group_content-&gt;getContentPlugin()-&gt;getPluginId() == 'group_membership') {
    $account = $group_content-&gt;getEntity();
    $group = $group_content-&gt;getGroup();    
    // Create the message
  }
}

This is untested so may need tweaking, but it should be close enough to get going.