Loading core/modules/field_ui/src/Form/FieldStorageAddForm.php +14 −17 Original line number Diff line number Diff line Loading @@ -381,12 +381,10 @@ public function validateForm(array &$form, FormStateInterface $form_state) { */ 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.')); Loading @@ -400,7 +398,6 @@ protected function validateAddNew(array $form, FormStateInterface $form_state) { $form_state->setValueForElement($form['new_storage_wrapper']['field_name'], $field_name); } } } /** * {@inheritdoc} Loading core/modules/field_ui/tests/src/FunctionalJavascript/ManageFieldsTest.php +12 −0 Original line number Diff line number Diff line Loading @@ -348,4 +348,16 @@ public function testAllowedValuesFormValidation() { $this->assertSession()->pageTextContains('Limit must be higher than or equal to 1.'); } /** * Tests the form validation for label field. */ public function testLabelFieldFormValidation() { $this->drupalGet('/admin/structure/types/manage/article/fields/add-field'); $page = $this->getSession()->getPage(); $page->findButton('Continue')->click(); $this->assertSession()->pageTextContains('You need to provide a label.'); $this->assertSession()->pageTextContains('You need to select a field type.'); } } Loading
core/modules/field_ui/src/Form/FieldStorageAddForm.php +14 −17 Original line number Diff line number Diff line Loading @@ -381,12 +381,10 @@ public function validateForm(array &$form, FormStateInterface $form_state) { */ 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.')); Loading @@ -400,7 +398,6 @@ protected function validateAddNew(array $form, FormStateInterface $form_state) { $form_state->setValueForElement($form['new_storage_wrapper']['field_name'], $field_name); } } } /** * {@inheritdoc} Loading
core/modules/field_ui/tests/src/FunctionalJavascript/ManageFieldsTest.php +12 −0 Original line number Diff line number Diff line Loading @@ -348,4 +348,16 @@ public function testAllowedValuesFormValidation() { $this->assertSession()->pageTextContains('Limit must be higher than or equal to 1.'); } /** * Tests the form validation for label field. */ public function testLabelFieldFormValidation() { $this->drupalGet('/admin/structure/types/manage/article/fields/add-field'); $page = $this->getSession()->getPage(); $page->findButton('Continue')->click(); $this->assertSession()->pageTextContains('You need to provide a label.'); $this->assertSession()->pageTextContains('You need to select a field type.'); } }