Skip to content
Snippets Groups Projects
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
20 merge requests!8376Drupal views: adding more granularity to the ‘use ajax’ functionality,!8300Issue #3443586 View area displays even when parent view has no results.,!7567Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7565Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7509Change label "Block description" to "Block type",!7344Issue #3292350 by O'Briat, KlemenDEV, hswong3i, smustgrave, quietone: Update...,!6922Issue #3412959 by quietone, smustgrave, longwave: Fix 12 'un' words,!6848Issue #3417553 by longwave: Remove withConsecutive() in CacheCollectorTest,!6720Revert "Issue #3358581 by pfrenssen, _tarik_, a.dmitriiev, smustgrave:...,!6560Update ClaroPreRender.php, confirming classes provided are in array format,!6528Issue #3414261 by catch: Add authenticated user umami performance tests,!6501Issue #3263668 by omkar-pd, Wim Leers, hooroomoo: Re-enable inline form errors...,!6354Draft: Issue #3380392 by phma: Updating language weight from the overview reverts label if translated,!6324Issue #3416723 by Ludo.R: Provide a "node type" views default argument,!6119Issue #3405704 by Spokje, longwave: symfony/psr-http-message-bridge major version bump,!5950Issue #3403653 by alexpott, longwave: Incorporate improvements to how contrib runs PHPStan to core,!5858Issue #3401971 by fjgarlin: Test-only job shouldn't require constant rebases...,!5716Draft: Issue #3401102 by Spokje, longwave, smustgrave: Nightwatch artifacts on GitLab not retained,!5674Transaction autocommit during shutdown relies on unreliable object destruction order,!5644Issue #3395563 by nireneko, marvil07, lauriii, borisson_, smustgrave, Wim...
Pipeline #57782 passed with warnings
Pipeline: drupal

#57807

    Pipeline: drupal

    #57800

      Pipeline: drupal

      #57791

        +1
        ......@@ -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.
        Please register or to comment