You are here

public function RequestHashForm::submitForm in Simplenews 8.2

Same name and namespace in other branches
  1. 8 src/Form/RequestHashForm.php \Drupal\simplenews\Form\RequestHashForm::submitForm()
  2. 3.x src/Form/RequestHashForm.php \Drupal\simplenews\Form\RequestHashForm::submitForm()

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/RequestHashForm.php, line 76

Class

RequestHashForm
Provides an generic base class for a confirmation form.

Namespace

Drupal\simplenews\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $params['from'] = \Drupal::service('simplenews.mailer')
    ->getFrom();
  $params['context'] = $form_state
    ->get('context');
  $subscriber = $params['context']['simplenews_subscriber'];
  \Drupal::service('plugin.manager.mail')
    ->mail('simplenews', $form_state
    ->get('key'), $subscriber
    ->getMail(), $subscriber
    ->getLangcode(), $params, $params['from']['address']);
  $this
    ->messenger()
    ->addMessage($this
    ->t('The confirmation mail has been sent.'));
  $form_state
    ->setRedirect('<front>');
}