protected FieldStorageAddForm::validateAddNew(array $form, FormStateInterface $form_state)
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()
File
- core/modules/field_ui/src/Form/FieldStorageAddForm.php, line 257
Class
- FieldStorageAddForm
- Provides a form for the "field storage" add page.
Namespace
Drupal\field_ui\Form
Code
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.')); } // Field name validation. 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); } } }
Please login to continue.