RequestHashForm.php in Simplenews 8
File
src/Form/RequestHashForm.php
View source
<?php
namespace Drupal\simplenews\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class RequestHashForm extends ConfirmFormBase {
public function getQuestion() {
return t('This link has expired.');
}
public function getDescription() {
return '';
}
public function getConfirmText() {
return t('Request new confirmation mail');
}
public function getFormId() {
return 'simplenews_request_hash';
}
public function getCancelUrl() {
return new Url('simplenews.newsletter_subscriptions');
}
public function buildForm(array $form, FormStateInterface $form_state, $key = '', $context = array()) {
$form = parent::buildForm($form, $form_state);
$form_state
->set('key', $key);
$form_state
->set('context', $context);
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
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(t('The confirmation mail has been sent.'));
$form_state
->setRedirect('<front>');
}
}