public function GroupCoreCommentsController::quickJoinGroup in Open Social 10.2.x
Same name and namespace in other branches
- 8.9 modules/custom/group_core_comments/src/Controller/GroupCoreCommentsController.php \Drupal\group_core_comments\Controller\GroupCoreCommentsController::quickJoinGroup()
- 8.8 modules/custom/group_core_comments/src/Controller/GroupCoreCommentsController.php \Drupal\group_core_comments\Controller\GroupCoreCommentsController::quickJoinGroup()
- 10.3.x modules/custom/group_core_comments/src/Controller/GroupCoreCommentsController.php \Drupal\group_core_comments\Controller\GroupCoreCommentsController::quickJoinGroup()
- 10.0.x modules/custom/group_core_comments/src/Controller/GroupCoreCommentsController.php \Drupal\group_core_comments\Controller\GroupCoreCommentsController::quickJoinGroup()
- 10.1.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\ControllerCode
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);
}