public function SocialAddToCalendarSettingsForm::buildForm in Open Social 8.9
Same name and namespace in other branches
- 10.3.x modules/social_features/social_event/modules/social_event_addtocal/src/Form/SocialAddToCalendarSettingsForm.php \Drupal\social_event_addtocal\Form\SocialAddToCalendarSettingsForm::buildForm()
 - 10.0.x modules/social_features/social_event/modules/social_event_addtocal/src/Form/SocialAddToCalendarSettingsForm.php \Drupal\social_event_addtocal\Form\SocialAddToCalendarSettingsForm::buildForm()
 - 10.1.x modules/social_features/social_event/modules/social_event_addtocal/src/Form/SocialAddToCalendarSettingsForm.php \Drupal\social_event_addtocal\Form\SocialAddToCalendarSettingsForm::buildForm()
 - 10.2.x modules/social_features/social_event/modules/social_event_addtocal/src/Form/SocialAddToCalendarSettingsForm.php \Drupal\social_event_addtocal\Form\SocialAddToCalendarSettingsForm::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_addtocal/ src/ Form/ SocialAddToCalendarSettingsForm.php, line 66  
Class
- SocialAddToCalendarSettingsForm
 - Class SocialAddToCalendarSettingsForm.
 
Namespace
Drupal\social_event_addtocal\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('social_event_addtocal.settings');
  // Enable the 'Add to calendar' feature.
  $form['enable_add_to_calendar'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable the <em>Add to calendar</em> button'),
    '#description' => $this
      ->t('If enabled, logged-in users are allowed to add the event to own calendar'),
    '#default_value' => $config
      ->get('enable_add_to_calendar'),
  ];
  // Get all calendar plugins and generate options.
  $addtocal_options = [];
  $addtocal_definitions = $this->addToCalendarManager
    ->getDefinitions();
  foreach ($addtocal_definitions as $addtocal_definition) {
    $addtocal_options[$addtocal_definition['id']] = $addtocal_definition['label'];
  }
  // Allowed calendars.
  $form['allowed_calendars'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Allowed calendars'),
    '#description' => $this
      ->t('Enable calendars you want to allow users to use'),
    '#options' => $addtocal_options,
    '#states' => [
      'visible' => [
        ':input[name="enable_add_to_calendar"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
    '#default_value' => $config
      ->get('allowed_calendars') ?: [],
  ];
  return parent::buildForm($form, $form_state);
}