You are here

public function ApprovalPollViewForm::cancel in Advanced Poll 8

Cancel vote submit function.

Parameters

array $form: The previous form.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

Overrides PollViewForm::cancel

File

src/Form/ApprovalPollViewForm.php, line 222

Class

ApprovalPollViewForm
Class ApprovalPollViewForm

Namespace

Drupal\advpoll\Form

Code

public function cancel(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\poll\PollVoteStorageInterface $vote_storage */
  $vote_storage = \Drupal::service('poll_vote.storage');
  $vote_storage
    ->cancelVote($this->poll, $this
    ->currentUser());
  \Drupal::logger('poll')
    ->notice('%user\'s vote in Poll #%poll deleted.', array(
    '%user' => $this
      ->currentUser()
      ->id(),
    '%poll' => $this->poll
      ->id(),
  ));
  \Drupal::messenger()
    ->addMessage($this
    ->t('Your vote was cancelled.'));

  // In case of an ajax submission, trigger a form rebuild so that we can
  // return an updated form through the ajax callback.
  if ($this
    ->getRequest()->query
    ->get('ajax_form')) {
    $form_state
      ->setRebuild(TRUE);
  }
}