You are here

public function AddMembersToGroup::execute in Open Social 8.7

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_group/src/Plugin/Action/AddMembersToGroup.php \Drupal\social_group\Plugin\Action\AddMembersToGroup::execute()
  2. 8.5 modules/social_features/social_group/src/Plugin/Action/AddMembersToGroup.php \Drupal\social_group\Plugin\Action\AddMembersToGroup::execute()
  3. 8.6 modules/social_features/social_group/src/Plugin/Action/AddMembersToGroup.php \Drupal\social_group\Plugin\Action\AddMembersToGroup::execute()
  4. 8.8 modules/social_features/social_group/src/Plugin/Action/AddMembersToGroup.php \Drupal\social_group\Plugin\Action\AddMembersToGroup::execute()
  5. 10.3.x modules/social_features/social_group/src/Plugin/Action/AddMembersToGroup.php \Drupal\social_group\Plugin\Action\AddMembersToGroup::execute()
  6. 10.0.x modules/social_features/social_group/src/Plugin/Action/AddMembersToGroup.php \Drupal\social_group\Plugin\Action\AddMembersToGroup::execute()
  7. 10.1.x modules/social_features/social_group/src/Plugin/Action/AddMembersToGroup.php \Drupal\social_group\Plugin\Action\AddMembersToGroup::execute()
  8. 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\Action

Code

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');
}