You are here

public function CommentNotifySettings::submitForm in Comment Notify 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides ConfigFormBase::submitForm

File

src/Form/CommentNotifySettings.php, line 364

Class

CommentNotifySettings
Settings form for the Comment Notify module.

Namespace

Drupal\comment_notify\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config = $this
    ->config('comment_notify.settings');
  $config
    ->set('bundle_types', array_keys(array_filter($form_state
    ->getValue('bundle_types'))));
  $config
    ->set('available_alerts', $form_state
    ->getValue('available_alerts'));
  $config
    ->set('enable_default', $form_state
    ->getValue('enable_default'));
  $bundle_checkboxes = $this
    ->getCommentFieldIdentifiers();
  foreach ($bundle_checkboxes as $identifier => $label) {
    $comment_field_info = explode('--', $identifier);
    $entity_type = $comment_field_info[0];
    $config
      ->set("mail_templates.watcher.{$entity_type}.subject", $form_state
      ->getValue([
      'mail_templates',
      'watcher',
      $entity_type,
      'subject',
    ]));
    $config
      ->set("mail_templates.watcher.{$entity_type}.body", $form_state
      ->getValue([
      'mail_templates',
      'watcher',
      $entity_type,
      'body',
    ]));
    $config
      ->set("mail_templates.entity_author.{$entity_type}.subject", $form_state
      ->getValue([
      'mail_templates',
      'entity_author',
      $entity_type,
      'subject',
    ]));
    $config
      ->set("mail_templates.entity_author.{$entity_type}.body", $form_state
      ->getValue([
      'mail_templates',
      'entity_author',
      $entity_type,
      'body',
    ]));
  }
  $config
    ->save();
  parent::submitForm($form, $form_state);
}