コード例 #1
0
 /**
  * {@inheritdoc}
  */
 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);
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $snid = NULL, $timestamp = NULL, $hash = NULL)
 {
     $user = \Drupal::currentUser();
     if ($subscriber = simplenews_subscriber_load_by_uid($user->id())) {
         $this->setEntity($subscriber);
     } elseif ($mail = $user->getEmail()) {
         $this->setEntity(Subscriber::create(array('mail' => $mail)));
     } elseif ($snid && $timestamp && $hash) {
         $subscriber = simplenews_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);
 }