You are here

public function EventAnEnrollSettingsForm::buildForm in Open Social 8.8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollSettingsForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollSettingsForm::buildForm()
  2. 8.3 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollSettingsForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollSettingsForm::buildForm()
  3. 8.4 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollSettingsForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollSettingsForm::buildForm()
  4. 8.5 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollSettingsForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollSettingsForm::buildForm()
  5. 8.6 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollSettingsForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollSettingsForm::buildForm()
  6. 8.7 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollSettingsForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollSettingsForm::buildForm()
  7. 10.3.x modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollSettingsForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollSettingsForm::buildForm()
  8. 10.0.x modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollSettingsForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollSettingsForm::buildForm()
  9. 10.1.x modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollSettingsForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollSettingsForm::buildForm()
  10. 10.2.x modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollSettingsForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollSettingsForm::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 ConfigFormBase::buildForm

File

modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollSettingsForm.php, line 32

Class

EventAnEnrollSettingsForm
Class EventAnEnrollSettingsForm.

Namespace

Drupal\social_event_an_enroll\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $event_an_enroll_config = $this
    ->config('social_event_an_enroll.settings');
  $form['event_an_enroll'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable event enrollment for anonymous users'),
    '#description' => $this
      ->t('Enabling this feature provides event organisers with the possibility to allow anonymous users to enroll in public events.'),
    '#default_value' => $event_an_enroll_config
      ->get('event_an_enroll'),
  ];

  // Show the additional settings only when AN enroll is enabled.
  $form['event_an_enroll_default_value'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Allow anonymous users to enroll in new events by default'),
    '#description' => $this
      ->t('When this setting is enabled, anonymous users are allowed to enroll in newly created events by default. The event organiser will still be able to change this if they have the permission.'),
    '#default_value' => $event_an_enroll_config
      ->get('event_an_enroll_default_value'),
    '#states' => [
      'visible' => [
        'input[name="event_an_enroll"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['event_an_enroll_allow_edit'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Allow the author of an event to decide whether anonymous users can or cannot enroll in the event'),
    '#description' => $this
      ->t('This will provide event organisers with the permission to decide whether anonymous users can enroll in their event.'),
    '#default_value' => $event_an_enroll_config
      ->get('event_an_enroll_allow_edit'),
    '#states' => [
      'visible' => [
        'input[name="event_an_enroll_default_value"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['event_an_enroll_email_notify'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Notify user by email after anonymous enrollment'),
    '#default_value' => $event_an_enroll_config
      ->get('event_an_enroll_email_notify'),
    '#states' => [
      'visible' => [
        'input[name="event_an_enroll"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['event_an_enroll_email'] = [
    '#type' => 'details',
    '#open' => TRUE,
    '#title' => $this
      ->t('Email notification'),
    '#group' => 'email',
    '#states' => [
      // Hide the additional settings when notification is disabled.
      'visible' => [
        'input[name="event_an_enroll"]' => [
          'checked' => TRUE,
        ],
        'input[name="event_an_enroll_email_notify"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['event_an_enroll_email']['event_an_enroll_email_subject'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Subject'),
    '#default_value' => $event_an_enroll_config
      ->get('event_an_enroll_email_subject'),
    '#maxlength' => 180,
  ];
  $form['event_an_enroll_email']['event_an_enroll_email_body'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Body'),
    '#default_value' => $event_an_enroll_config
      ->get('event_an_enroll_email_body'),
    '#rows' => 15,
  ];

  // Add explanation about using tokens.
  $form['event_an_enroll_email']['event_an_enroll_email_token'] = [
    '#markup' => $this
      ->t('To add the event name and link, use the following tokens: [node:title], [social_event_an_enroll:enrolled_event]'),
  ];
  return parent::buildForm($form, $form_state);
}