public function PollForm::validateForm in Poll 8
Button-level validation handlers are highly discouraged for entity forms, as they will prevent entity validation from running. If the entity is going to be saved during the form submission, this method should be manually invoked from the button-level validation handler, otherwise an exception will be thrown.
Overrides ContentEntityForm::validateForm
File
- src/
Form/ PollForm.php, line 42
Class
- PollForm
- Form controller for the poll edit forms.
Namespace
Drupal\poll\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$poll = $this
->buildEntity($form, $form_state);
// Check for duplicate titles.
$poll_storage = $this->entityTypeManager
->getStorage('poll');
$result = $poll_storage
->getPollDuplicates($poll);
foreach ($result as $item) {
if (strcasecmp($item
->label(), $poll
->label()) == 0) {
$form_state
->setErrorByName('question', $this
->t('A feed named %feed already exists. Enter a unique question.', array(
'%feed' => $poll
->label(),
)));
}
}
parent::validateForm($form, $form_state);
}