public function AddMembersToGroup::execute in Open Social 8.7
Same name and namespace in other branches
- 8.9 modules/social_features/social_group/src/Plugin/Action/AddMembersToGroup.php \Drupal\social_group\Plugin\Action\AddMembersToGroup::execute()
- 8.5 modules/social_features/social_group/src/Plugin/Action/AddMembersToGroup.php \Drupal\social_group\Plugin\Action\AddMembersToGroup::execute()
- 8.6 modules/social_features/social_group/src/Plugin/Action/AddMembersToGroup.php \Drupal\social_group\Plugin\Action\AddMembersToGroup::execute()
- 8.8 modules/social_features/social_group/src/Plugin/Action/AddMembersToGroup.php \Drupal\social_group\Plugin\Action\AddMembersToGroup::execute()
- 10.3.x modules/social_features/social_group/src/Plugin/Action/AddMembersToGroup.php \Drupal\social_group\Plugin\Action\AddMembersToGroup::execute()
- 10.0.x modules/social_features/social_group/src/Plugin/Action/AddMembersToGroup.php \Drupal\social_group\Plugin\Action\AddMembersToGroup::execute()
- 10.1.x modules/social_features/social_group/src/Plugin/Action/AddMembersToGroup.php \Drupal\social_group\Plugin\Action\AddMembersToGroup::execute()
- 10.2.x modules/social_features/social_group/src/Plugin/Action/AddMembersToGroup.php \Drupal\social_group\Plugin\Action\AddMembersToGroup::execute()
File
- modules/
social_features/ social_group/ src/ Plugin/ Action/ AddMembersToGroup.php, line 73
Class
- AddMembersToGroup
- Change group membership role.
Namespace
Drupal\social_group\Plugin\ActionCode
public function execute($entity = NULL) {
// Load the Group.
$group = Group::load($this->configuration['groups']);
if (NULL !== $group) {
// Check if user already is a member.
$is_member = $group
->getMember($entity);
// If that is not the case we can add it to the group.
if (!$is_member) {
$group
->addMember($entity);
return $this
->t('Amount of users added to group');
}
// Return this when user is already a member.
return $this
->t('Amount of existing members');
}
// Fail safe if something went wrong.
return $this
->t('Amount of users added not added');
}