public function GroupSubscribeForm::buildForm in Organic groups 8
Overrides EntityForm::buildForm
See also
\Drupal\Core\Entity\EntityConfirmFormBase::buildForm
File
- src/
Form/ GroupSubscribeForm.php, line 130
Class
- GroupSubscribeForm
- Provides a form for subscribing to a group.
Namespace
Drupal\og\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$state = $this
->isStateActive() ? OgMembershipInterface::STATE_ACTIVE : OgMembershipInterface::STATE_PENDING;
/** @var \Drupal\og\OgMembershipInterface $membership */
$membership = $this->entity;
$membership
->setState($state);
// Add confirmation related elements.
$form['#title'] = $this
->getQuestion();
$form['#attributes']['class'][] = 'confirmation';
$form['description'] = [
'#markup' => $this
->t('This action cannot be undone.'),
];
$form['confirm'] = [
'#type' => 'hidden',
'#value' => 1,
];
// By default, render the form using theme_confirm_form().
if (!isset($form['#theme'])) {
$form['#theme'] = 'confirm_form';
}
$form = parent::buildForm($form, $form_state);
if ($this
->isStateActive() && !empty($form[OgMembershipInterface::REQUEST_FIELD])) {
// State is active, so no need to show the request field, as the user
// will not need any approval for joining.
$form[OgMembershipInterface::REQUEST_FIELD]['#access'] = FALSE;
}
return $form;
}