SubscriptionsPageForm.php in Simplenews 8.2
File
src/Form/SubscriptionsPageForm.php
View source
<?php
namespace Drupal\simplenews\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\simplenews\Entity\Subscriber;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class SubscriptionsPageForm extends SubscriptionsFormBase {
public function buildForm(array $form, FormStateInterface $form_state, $snid = NULL, $timestamp = NULL, $hash = NULL) {
$user = \Drupal::currentUser();
if (!$user
->isAnonymous()) {
$this
->setEntity(Subscriber::loadByUid($user
->id(), 'create'));
}
elseif ($snid && $timestamp && $hash) {
$subscriber = Subscriber::load($snid);
if ($subscriber && $hash == simplenews_generate_hash($subscriber
->getMail(), 'manage', $timestamp)) {
$this
->setEntity($subscriber);
}
else {
throw new NotFoundHttpException();
}
}
return parent::buildForm($form, $form_state);
}
protected function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state);
$actions[static::SUBMIT_UPDATE]['#value'] = $this
->t('Update');
return $actions;
}
protected function getSubmitMessage(FormStateInterface $form_state, $op, $confirm) {
if ($confirm) {
switch ($op) {
case static::SUBMIT_SUBSCRIBE:
return $this
->t('You will receive a confirmation e-mail shortly containing further instructions on how to complete your subscription.');
case static::SUBMIT_UNSUBSCRIBE:
return $this
->t('You will receive a confirmation e-mail shortly containing further instructions on how to cancel your subscription.');
}
}
return $this
->t('The newsletter subscriptions for %mail have been updated.', [
'%mail' => $form_state
->getValue('mail')[0]['value'],
]);
}
}