Skip to content
Snippets Groups Projects
Verified Commit 5ed165d5 authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3403101 by Utkarsh_33, omkar.podey, Nitin shrivastava, narendraR: Label...

Issue #3403101 by Utkarsh_33, omkar.podey, Nitin shrivastava, narendraR: Label field need validation on the FieldStorageAddForm
parent a6a0523e
No related branches found
No related tags found
No related merge requests found
......@@ -381,24 +381,21 @@ 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.'));
}
// Field name validation.
else {
$field_name = $form_state->getValue('field_name');
// 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);
}
// 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);
}
}
......
......@@ -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.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment