You are here

public function MessageNotifyForm::buildForm in Message UI 8

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 EntityForm::buildForm

File

modules/message_notify_ui/src/Form/MessageNotifyForm.php, line 138

Class

MessageNotifyForm
Provides a form for send a message entity.

Namespace

Drupal\message_notify_ui\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['actions'] = parent::buildForm($form, $form_state)['actions'];
  $senders = [];
  foreach ($this->messageNotifierManager
    ->getDefinitions() as $definition) {
    $senders[$definition['id']] = $definition['title'];
  }
  $senders_ids = array_keys($senders);
  $form['senders'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Select a notifier handler'),
    '#options' => $senders,
    '#default_value' => reset($senders_ids),
  ];
  $form['senders_form'] = [];
  if ($this->languageManager
    ->isMultilingual()) {

    // Multilingual is on. Add languages to the select list.
    $languages = [];
    foreach ($this->languageManager
      ->getLanguages() as $language) {
      $languages[$language
        ->getId()] = $language
        ->getName();
    }
    $form['language'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Select a language'),
      '#options' => $languages,
    ];
  }
  foreach ($this->messageNotifyUiSenderSettingsForm
    ->getDefinitions() as $definition) {
    $plugin = $this->messageNotifyUiSenderSettingsForm
      ->createInstance($definition['id']);
    $this->plugins[$definition['notify_plugin']] = $definition['id'];
    $form['senders_form'][$definition['id']] = $plugin
      ->form();
  }
  $form['actions'] = [
    '#type' => 'actions',
    'submit' => [
      '#type' => 'submit',
      '#value' => $this
        ->t('Notify'),
      '#submit' => [
        '::submitForm',
        '::save',
      ],
      '#button_type' => 'primary',
    ],
  ];
  return $form;
}