public FieldStorageAddForm::validateForm(array &$form, FormStateInterface $form_state)
Form validation handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormBase::validateForm
File
- core/modules/field_ui/src/Form/FieldStorageAddForm.php, line 231
Class
- FieldStorageAddForm
- Provides a form for the "field storage" add page.
Namespace
Drupal\field_ui\Form
Code
public function validateForm(array &$form, FormStateInterface $form_state) {
// Missing field type.
if (!$form_state->getValue('new_storage_type') && !$form_state->getValue('existing_storage_name')) {
$form_state->setErrorByName('new_storage_type', $this->t('You need to select a field type or an existing field.'));
}
// Both field type and existing field option selected. This is prevented in
// the UI with JavaScript but we also need a proper server-side validation.
elseif ($form_state->getValue('new_storage_type') && $form_state->getValue('existing_storage_name')) {
$form_state->setErrorByName('new_storage_type', $this->t('Adding a new field and re-using an existing field at the same time is not allowed.'));
return;
}
$this->validateAddNew($form, $form_state);
$this->validateAddExisting($form, $form_state);
}
Please login to continue.