Verified Commit b52f3a06 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

(cherry picked from commit 5ed165d5)
parent 6c3b0d58
Loading
Loading
Loading
Loading
Loading
+14 −17
Original line number Diff line number Diff line
@@ -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.'));
@@ -400,7 +398,6 @@ protected function validateAddNew(array $form, FormStateInterface $form_state) {
      $form_state->setValueForElement($form['new_storage_wrapper']['field_name'], $field_name);
    }
  }
  }

  /**
   * {@inheritdoc}
+12 −0
Original line number Diff line number Diff line
@@ -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.');
  }

}