You are here

public function FieldStorageAddForm::validateForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/field_ui/src/Form/FieldStorageAddForm.php \Drupal\field_ui\Form\FieldStorageAddForm::validateForm()
  2. 10 core/modules/field_ui/src/Form/FieldStorageAddForm.php \Drupal\field_ui\Form\FieldStorageAddForm::validateForm()

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 263

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.'));
  }
  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);
}