public function ContactEmailForm::validateForm in Contact Emails 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/ ContactEmailForm.php, line 325
Class
- ContactEmailForm
- Defines the tax service add/edit form.
Namespace
Drupal\contact_emails\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
// Require recipients if manual recipient type.
if ($values['recipient_type'][0]['value'] == 'manual' && !$values['recipients'][0]['value']) {
$form_state
->setErrorByName('recipients', $this
->t('Please add at least one recipient.'));
}
// Require field if field recipient type.
if ($values['recipient_type'][0]['value'] == 'field' && !$values['recipient_field'][0]['value']) {
$form_state
->setErrorByName('recipient_field', $this
->t('Please select a field with the email type to use this recipient type.'));
}
// Require reference field if reference recipient type.
if ($values['recipient_type'][0]['value'] == 'reference' && !$values['recipient_reference'][0]['value']) {
$form_state
->setErrorByName('recipient_reference', $this
->t('Please select a referenced field with the email type to use this recipient type.'));
}
// Require field if field reply-to type.
if ($values['reply_to_type'][0]['value'] == 'field' && !$values['reply_to_field'][0]['value']) {
$form_state
->setErrorByName('reply_to_field', $this
->t('Please select a field with the email type to use this reply-to type.'));
}
// Require email if email reply-to type.
if ($values['reply_to_type'][0]['value'] == 'manual' && !$values['reply_to_email'][0]['value']) {
$form_state
->setErrorByName('reply_to_email', $this
->t('Please enter a reply-to email address to use this reply-to type.'));
}
// Require reference field if reference reply to type.
if ($values['reply_to_type'][0]['value'] == 'reference' && !$values['reply_to_reference'][0]['value']) {
$form_state
->setErrorByName('reply_to_reference', $this
->t('Please select a reference field to use this reply-to type.'));
}
parent::validateForm($form, $form_state);
}