function FieldStorageAddForm::validateAddNew
Same name in other branches
- 8.9.x core/modules/field_ui/src/Form/FieldStorageAddForm.php \Drupal\field_ui\Form\FieldStorageAddForm::validateAddNew()
Validates the 'add new field' case.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
See also
\Drupal\field_ui\Form\FieldStorageAddForm::validateForm()
1 call to FieldStorageAddForm::validateAddNew()
- FieldStorageAddForm::validateForm in core/
modules/ field_ui/ src/ Form/ FieldStorageAddForm.php - Form validation handler.
File
-
core/
modules/ field_ui/ src/ Form/ FieldStorageAddForm.php, line 269
Class
- FieldStorageAddForm
- Provides a form for the "field storage" add page.
Namespace
Drupal\field_ui\FormCode
protected function validateAddNew(array $form, FormStateInterface $form_state) {
// Validate if any information was provided in the 'add new field' case.
if ($form_state->getValue('new_storage_type')) {
// Missing label.
if (!$form_state->getValue('label')) {
$form_state->setErrorByName('label', $this->t('Add new field: you need to provide a label.'));
}
// Missing field name.
if (!$form_state->getValue('field_name')) {
$form_state->setErrorByName('field_name', $this->t('Add new field: you need to provide a machine name for the field.'));
}
else {
$field_name = $form_state->getValue('field_name');
// Add the field prefix.
$field_name = $this->configFactory
->get('field_ui.settings')
->get('field_prefix') . $field_name;
$form_state->setValueForElement($form['new_storage_wrapper']['field_name'], $field_name);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.