You are here

public function MailEditTemplateForm::submitForm in Mail Editor 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 FormInterface::submitForm

File

src/Form/MailEditTemplateForm.php, line 112

Class

MailEditTemplateForm
Edit an email template.

Namespace

Drupal\mail_edit\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Work out the template ID.
  $id = $form_state
    ->getValue('id');

  // Get the config object for this template.
  $configFactory = $this
    ->configFactory()
    ->getEditable($this
    ->getConfigName($id));
  $name = $this
    ->getEmailName($id);

  // Update the config object.
  $configFactory
    ->set($name . '.subject', $form_state
    ->getValue('subject'));
  $configFactory
    ->set($name . '.body', $form_state
    ->getValue('body'));
  $configFactory
    ->save();
  $this
    ->messenger()
    ->addMessage($this
    ->t('Email "%mesg" has been updated.', [
    '%mesg' => $name,
  ]));
  $form_state
    ->setRedirect('mail_edit.list');
}