You are here

public function SubscriberValidateForm::buildForm in Simplenews 3.x

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 FormInterface::buildForm

File

src/Form/SubscriberValidateForm.php, line 66

Class

SubscriberValidateForm
Do a mass subscription for a list of email addresses.

Namespace

Drupal\simplenews\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $user = $this
    ->currentUser();
  if ($user
    ->isAuthenticated()) {
    return new RedirectResponse(Url::fromRoute('simplenews.newsletter_subscriptions_user', [
      'user' => $user
        ->id(),
    ])
      ->toString());
  }
  $form['explain'] = [
    '#prefix' => '<p>',
    '#markup' => $this
      ->t('Request an email with a link to manage your subscriptions.'),
    '#suffix' => '</p>',
  ];
  $form['mail'] = [
    '#type' => 'email',
    '#title' => $this
      ->t('Email'),
    '#description' => $this
      ->t('Subscribed email address'),
    '#required' => TRUE,
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Submit'),
  ];
  return $form;
}