You are here

public function GroupRequestMembershipRequestForm::submitForm in Open Social 10.2.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_group/modules/social_group_request/src/Form/GroupRequestMembershipRequestForm.php \Drupal\social_group_request\Form\GroupRequestMembershipRequestForm::submitForm()
  2. 10.3.x modules/social_features/social_group/modules/social_group_request/src/Form/GroupRequestMembershipRequestForm.php \Drupal\social_group_request\Form\GroupRequestMembershipRequestForm::submitForm()
  3. 10.0.x modules/social_features/social_group/modules/social_group_request/src/Form/GroupRequestMembershipRequestForm.php \Drupal\social_group_request\Form\GroupRequestMembershipRequestForm::submitForm()
  4. 10.1.x modules/social_features/social_group/modules/social_group_request/src/Form/GroupRequestMembershipRequestForm.php \Drupal\social_group_request\Form\GroupRequestMembershipRequestForm::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

modules/social_features/social_group/modules/social_group_request/src/Form/GroupRequestMembershipRequestForm.php, line 127

Class

GroupRequestMembershipRequestForm
Provides a form to request group membership.

Namespace

Drupal\social_group_request\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $content_type_config_id = $this->group
    ->getGroupType()
    ->getContentPlugin('group_membership_request')
    ->getContentTypeConfigId();
  $group_content = $this->entityTypeManager
    ->getStorage('group_content')
    ->create([
    'type' => $content_type_config_id,
    'gid' => $this->group
      ->id(),
    'entity_id' => $this
      ->currentUser()
      ->id(),
    'grequest_status' => GroupMembershipRequest::REQUEST_PENDING,
    'field_grequest_message' => $form_state
      ->getValue('message'),
  ]);
  $result = $group_content
    ->save();
  if ($result) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('Your request has been sent successfully'));
  }
  else {
    $this
      ->messenger()
      ->addError($this
      ->t('Error when creating a request to join'));
  }
  $this->cacheTagsInvalidator
    ->invalidateTags([
    'request-membership:' . $this->group
      ->id(),
  ]);
  return $form_state
    ->setRedirect('social_group.stream', [
    'group' => $this->group
      ->id(),
  ]);
}