You are here

public function GroupCoreCommentsController::quickJoinGroup in Open Social 10.0.x

Same name and namespace in other branches
  1. 8.9 modules/custom/group_core_comments/src/Controller/GroupCoreCommentsController.php \Drupal\group_core_comments\Controller\GroupCoreCommentsController::quickJoinGroup()
  2. 8.8 modules/custom/group_core_comments/src/Controller/GroupCoreCommentsController.php \Drupal\group_core_comments\Controller\GroupCoreCommentsController::quickJoinGroup()
  3. 10.3.x modules/custom/group_core_comments/src/Controller/GroupCoreCommentsController.php \Drupal\group_core_comments\Controller\GroupCoreCommentsController::quickJoinGroup()
  4. 10.1.x modules/custom/group_core_comments/src/Controller/GroupCoreCommentsController.php \Drupal\group_core_comments\Controller\GroupCoreCommentsController::quickJoinGroup()
  5. 10.2.x modules/custom/group_core_comments/src/Controller/GroupCoreCommentsController.php \Drupal\group_core_comments\Controller\GroupCoreCommentsController::quickJoinGroup()

Callback to quick joining group.

Parameters

\Drupal\group\Entity\GroupInterface $group: Group entity.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse Redirect response.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Core\Entity\EntityStorageException

1 string reference to 'GroupCoreCommentsController::quickJoinGroup'
group_core_comments.routing.yml in modules/custom/group_core_comments/group_core_comments.routing.yml
modules/custom/group_core_comments/group_core_comments.routing.yml

File

modules/custom/group_core_comments/src/Controller/GroupCoreCommentsController.php, line 82

Class

GroupCoreCommentsController
Provides group core comments controllers.

Namespace

Drupal\group_core_comments\Controller

Code

public function quickJoinGroup(GroupInterface $group) {

  /** @var \Drupal\group\Plugin\GroupContentEnablerInterface $plugin */
  $plugin = $group
    ->getGroupType()
    ->getContentPlugin('group_membership');
  $group_content = $this
    ->entityTypeManager()
    ->getStorage('group_content')
    ->create([
    'type' => $plugin
      ->getContentTypeConfigId(),
    'gid' => $group
      ->id(),
    'entity_id' => $this
      ->currentUser()
      ->id(),
  ]);
  $result = $group_content
    ->save();
  if ($result) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('You have joined the group and you can leave your comment now.'));
  }
  else {
    $this
      ->messenger()
      ->addError($this
      ->t('Error when joining the group.'));
  }
  $previous_url = $this->requestService
    ->getCurrentRequest()->headers
    ->get('referer');
  $request = Request::create($previous_url);
  $referer_path = $request
    ->getRequestUri();
  return new RedirectResponse($referer_path);
}