You are here

public function GroupRequestController::requestMembership in Open Social 10.0.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_group/modules/social_group_request/src/Controller/GroupRequestController.php \Drupal\social_group_request\Controller\GroupRequestController::requestMembership()
  2. 10.3.x modules/social_features/social_group/modules/social_group_request/src/Controller/GroupRequestController.php \Drupal\social_group_request\Controller\GroupRequestController::requestMembership()
  3. 10.1.x modules/social_features/social_group/modules/social_group_request/src/Controller/GroupRequestController.php \Drupal\social_group_request\Controller\GroupRequestController::requestMembership()
  4. 10.2.x modules/social_features/social_group/modules/social_group_request/src/Controller/GroupRequestController.php \Drupal\social_group_request\Controller\GroupRequestController::requestMembership()

Callback to request membership.

File

modules/social_features/social_group/modules/social_group_request/src/Controller/GroupRequestController.php, line 123

Class

GroupRequestController
Returns responses for Group request routes.

Namespace

Drupal\social_group_request\Controller

Code

public function requestMembership(GroupInterface $group) {
  $response = new AjaxResponse();
  $contentTypeConfigId = $group
    ->getGroupType()
    ->getContentPlugin('group_membership_request')
    ->getContentTypeConfigId();
  $request = $this
    ->entityTypeManager()
    ->getStorage('group_content')
    ->getQuery()
    ->condition('type', $contentTypeConfigId)
    ->condition('gid', $group
    ->id())
    ->condition('entity_id', $this
    ->currentUser()
    ->id())
    ->condition('grequest_status', GroupMembershipRequest::REQUEST_PENDING)
    ->count()
    ->execute();
  if ($request == 0) {
    $request_form = $this
      ->formBuilder()
      ->getForm(GroupRequestMembershipRequestForm::class, $group);
    $response
      ->addCommand(new OpenModalDialogCommand($this
      ->t('Request to join'), $request_form, [
      'width' => '582px',
      'dialogClass' => 'social_group-popup',
    ]));
  }
  return $response;
}