/** * {@inheritdoc} */ protected function actions(array $form, FormStateInterface $form_state) { // If only one newsletter, show Subscribe/Unsubscribe instead of Update. $actions = parent::actions($form, $form_state); if ($this->getOnlyNewsletterId() != NULL) { $actions[static::SUBMIT_UPDATE]['#access'] = FALSE; $actions[static::SUBMIT_SUBSCRIBE]['#access'] = !$this->entity->isSubscribed($this->getOnlyNewsletterId()); $actions[static::SUBMIT_UNSUBSCRIBE]['#access'] = $this->entity->isSubscribed($this->getOnlyNewsletterId()); } return parent::actions($form, $form_state); }
/** * {@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); }
/** * {@inheritdoc} */ protected function actions(array $form, FormStateInterface $form_state) { $actions = parent::actions($form, $form_state); $actions[static::SUBMIT_UPDATE]['#value'] = $this->t('Save'); return $actions; }