You are here

public function RngSettingsForm::buildForm in RNG - Events and Registrations 8

Same name and namespace in other branches
  1. 8.2 src/Form/RngSettingsForm.php \Drupal\rng\Form\RngSettingsForm::buildForm()
  2. 3.x src/Form/RngSettingsForm.php \Drupal\rng\Form\RngSettingsForm::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

src/Form/RngSettingsForm.php, line 77

Class

RngSettingsForm
Configure primary RNG settings.

Namespace

Drupal\rng\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);
  $config = $this
    ->config('rng.settings');
  $identity_types = $config
    ->get('identity_types');
  $identity_types = is_array($identity_types) ? $identity_types : [];
  $form['contactables'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('People types'),
    '#description' => $this
      ->t('Enable people types who can register for events.'),
    '#open' => TRUE,
    '#tree' => TRUE,
  ];
  foreach ($this->identityChannelManager
    ->getIdentityTypes() as $identity_type) {
    $channels = $this->identityChannelManager
      ->getChannelsForIdentityType($identity_type);
    $channels_string = [];
    foreach ($channels as $channel) {
      if ($channel_entity_type = $this->entityTypeManager
        ->getDefinition($channel, FALSE)) {
        $channels_string[] = $channel_entity_type
          ->getLabel();
      }
    }
    if (!($entity_type = $this->entityTypeManager
      ->getDefinition($identity_type, FALSE))) {
      continue;
    }
    $form['contactables'][$identity_type] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('@label (@provider)', [
        '@label' => $entity_type
          ->getLabel(),
        '@provider' => $entity_type
          ->getProvider(),
      ]),
      '#description' => $this
        ->t('Supported channels: @channels', [
        '@channels' => implode(', ', $channels_string),
      ]),
      '#default_value' => in_array($identity_type, $identity_types),
    ];
  }
  return $form;
}