You are here

public function SubscriptionsAccountForm::buildForm in Simplenews 8.2

Same name and namespace in other branches
  1. 8 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 18

Class

SubscriptionsAccountForm
Configure simplenews subscriptions of a user.

Namespace

Drupal\simplenews\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, UserInterface $user = NULL) {
  if (isset($user)) {
    $form_state
      ->set('user', $user);

    // Load/create a subscriber from the user.
    $this
      ->setEntity(Subscriber::loadByUid($user
      ->id(), 'create'));
  }
  return parent::buildForm($form, $form_state);
}