You are here

public function SubscriptionsPageForm::buildForm in Simplenews 8.2

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

Form constructor.

Parameters

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

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

Return value

array The form structure.

Overrides EntityForm::buildForm

File

src/Form/SubscriptionsPageForm.php, line 17

Class

SubscriptionsPageForm
Configure simplenews subscriptions of the logged user.

Namespace

Drupal\simplenews\Form

Code

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);
}