You are here

public function SubscriptionsAccountForm::buildForm in Simplenews 8

Same name and namespace in other branches
  1. 8.2 src/Form/SubscriptionsAccountForm.php \Drupal\simplenews\Form\SubscriptionsAccountForm::buildForm()
  2. 3.x src/Form/SubscriptionsAccountForm.php \Drupal\simplenews\Form\SubscriptionsAccountForm::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/SubscriptionsAccountForm.php, line 17

Class

SubscriptionsAccountForm
Configure simplenews subscriptions of a user.

Namespace

Drupal\simplenews\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, UserInterface $user = NULL) {

  // Try to load a subscriber from the uid, otherwise just set the mail field
  // on the new subscriber.
  if (isset($user)) {
    $form_state
      ->set('user', $user);
    if ($subscriber = simplenews_subscriber_load_by_uid($user
      ->id())) {
      $this
        ->setEntity($subscriber);
    }
    else {
      $this->entity
        ->setUserId($user
        ->id());
      $this->entity
        ->setMail($user
        ->getEmail());
    }
  }
  return parent::buildForm($form, $form_state);
}