public function ApprovalPollViewForm::validateVote in Advanced Poll 8
Validates the vote action.
Parameters
array $form:
\Drupal\Core\Form\FormStateInterface $form_state:
Overrides PollViewForm::validateVote
File
- src/
Form/ ApprovalPollViewForm.php, line 164
Class
- ApprovalPollViewForm
- Class ApprovalPollViewForm
Namespace
Drupal\advpoll\FormCode
public function validateVote(array &$form, FormStateInterface $form_state) {
parent::validateVote($form, $form_state);
// Check multiple.
$maxChoices = $this
->getMaxChoices();
if ($maxChoices) {
// Check choices.
$choices = array_filter($form_state
->getValue('choice'));
// Check multiple write-in.
$writeInOptions = [];
if (isset($choices[self::writeInIndex])) {
$writeInOptions = $this
->getWriteInOptions($form_state);
// We don't need write-in checkbox because we use textfields.
unset($choices[self::writeInIndex]);
}
if (count($choices) + count($writeInOptions) > $maxChoices) {
$form_state
->setErrorByName('choice', $this
->t('Select up to @quantity @votes.', [
'@quantity' => $maxChoices,
'@votes' => $this
->formatPlural($maxChoices, 'vote', 'votes'),
]));
}
}
}