public function EventAnEnrollForm::buildForm in Open Social 8.8
Same name and namespace in other branches
- 8.9 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm::buildForm()
- 8.3 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm::buildForm()
- 8.4 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm::buildForm()
- 8.5 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm::buildForm()
- 8.6 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm::buildForm()
- 8.7 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm::buildForm()
- 10.3.x modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm::buildForm()
- 10.0.x modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm::buildForm()
- 10.1.x modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm::buildForm()
- 10.2.x modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides EnrollActionForm::buildForm
File
- modules/
social_features/ social_event/ modules/ social_event_an_enroll/ src/ Form/ EventAnEnrollForm.php, line 31
Class
- EventAnEnrollForm
- Class EventAnEnrollForm.
Namespace
Drupal\social_event_an_enroll\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$nid = $this->routeMatch
->getRawParameter('node');
// Load node object.
if (!is_null($nid) && !is_object($nid)) {
$node = Node::load($nid);
}
// Set hidden values.
$form['field_event'] = [
'#type' => 'hidden',
'#value' => $nid,
];
$form['field_first_name'] = [
'#type' => 'textfield',
'#title' => $this
->t('First name'),
];
$form['field_last_name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Last name'),
];
$form['field_email'] = [
'#type' => 'email',
'#required' => TRUE,
'#title' => $this
->t('Email address'),
'#description' => $this
->t('Enter your email, so we can send you event updates.'),
];
if ($this->moduleHandler
->moduleExists('data_policy')) {
$data_policy_config = $this->configFactory
->get('data_policy.data_policy');
// Check if data policy is created.
if (!empty($data_policy_config
->get('entity_id'))) {
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
$link = Link::createFromRoute($this
->t('data policy'), 'data_policy.data_policy', [], [
'attributes' => [
'class' => [
'use-ajax',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'title' => t('Data policy'),
'width' => 700,
'height' => 700,
]),
],
]);
$enforce_consent = !empty($data_policy_config
->get('enforce_consent'));
$form['data_policy'] = [
'#type' => 'checkbox',
'#title' => $this
->t('I agree with the @url', [
'@url' => $link
->toString(),
]),
'#required' => $enforce_consent,
];
}
}
$submit_text = $this
->t('Enroll in event');
$enrollment_open = TRUE;
// Add the enrollment closed label.
if ($this
->eventHasBeenFinished($node)) {
$submit_text = $this
->t('Event has passed');
$enrollment_open = FALSE;
}
$form['actions']['submit'] = [
'#type' => 'submit',
'#button_type' => 'primary',
'#button_level' => 'raised',
'#value' => $submit_text,
'#disabled' => !$enrollment_open,
];
return $form;
}