Skip to content
Snippets Groups Projects
Verified Commit 35b420b9 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3411419 by catch, lauriii, larowlan, kevinquillen: Regression from...

Issue #3411419 by catch, lauriii, larowlan, kevinquillen: Regression from #2521800: using machine name element for ListStringItem breaks with existing data

(cherry picked from commit 7ca3f9e2)
parent 0d0bcc3b
No related branches found
No related tags found
15 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
Pipeline #69956 passed
Pipeline: drupal

#69969

    Pipeline: drupal

    #69967

      Pipeline: drupal

      #69966

        +6
        ...@@ -100,6 +100,10 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state ...@@ -100,6 +100,10 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state
        // Workaround for https://drupal.org/i/1300290#comment-12873635. // Workaround for https://drupal.org/i/1300290#comment-12873635.
        \Drupal::service('plugin.manager.element_info')->getInfoProperty('machine_name', '#process', []), \Drupal::service('plugin.manager.element_info')->getInfoProperty('machine_name', '#process', []),
        ); );
        // Remove #element_validate from the machine name so that any value can be
        // used as a key, while keeping the widget's behavior for generating
        // defaults the same.
        $element['allowed_values']['table'][$delta]['item']['key']['#element_validate'] = [];
        } }
        return $element; return $element;
        ...@@ -113,6 +117,14 @@ public static function processAllowedValuesKey(array &$element): array { ...@@ -113,6 +117,14 @@ public static function processAllowedValuesKey(array &$element): array {
        array_pop($parents); array_pop($parents);
        $parents[] = 'label'; $parents[] = 'label';
        $element['#machine_name']['source'] = $parents; $element['#machine_name']['source'] = $parents;
        // Override the default description which is not applicable to this use of
        // the machine name element given that it allows users to manually enter
        // characters usually not allowed in machine names.
        if (!isset($element['#description'])) {
        $element['#description'] = '';
        }
        return $element; return $element;
        } }
        ......
        ...@@ -306,14 +306,15 @@ public function testOptionsAllowedValuesText() { ...@@ -306,14 +306,15 @@ public function testOptionsAllowedValuesText() {
        $field_storage = FieldStorageConfig::loadByName('node', $this->fieldName); $field_storage = FieldStorageConfig::loadByName('node', $this->fieldName);
        $this->assertSame($field_storage->getSetting('allowed_values'), ['zero' => 'Zero']); $this->assertSame($field_storage->getSetting('allowed_values'), ['zero' => 'Zero']);
        // Check that string values with dots can not be used. // Check that string values with special characters can be used.
        $input = [ $input = [
        'field_storage[subform][settings][allowed_values][table][0][item][key]' => 'zero', 'field_storage[subform][settings][allowed_values][table][0][item][key]' => 'zero',
        'field_storage[subform][settings][allowed_values][table][0][item][label]' => 'Zero', 'field_storage[subform][settings][allowed_values][table][0][item][label]' => 'Zero',
        'field_storage[subform][settings][allowed_values][table][1][item][key]' => 'example.com', 'field_storage[subform][settings][allowed_values][table][1][item][key]' => '.example #example',
        'field_storage[subform][settings][allowed_values][table][1][item][label]' => 'Example', 'field_storage[subform][settings][allowed_values][table][1][item][label]' => 'Example',
        ]; ];
        $this->assertAllowedValuesInput($input, 'The machine-readable name must contain only lowercase letters, numbers, and underscores.', 'String value with dot is not supported.'); $array = ['zero' => 'Zero', '.example #example' => 'Example'];
        $this->assertAllowedValuesInput($input, $array, '');
        // Check that the same key can only be used once. // Check that the same key can only be used once.
        $input = [ $input = [
        ......
        ...@@ -375,6 +375,37 @@ public function providerTestOptionsAllowedValues() { ...@@ -375,6 +375,37 @@ public function providerTestOptionsAllowedValues() {
        return $test_cases; return $test_cases;
        } }
        /**
        * Tests `list_string` machine name with special characters.
        */
        public function testMachineNameSpecialCharacters() {
        $this->fieldName = 'field_options_text';
        $this->createOptionsField('list_string');
        $this->drupalGet($this->adminPath);
        $label_element_name = "field_storage[subform][settings][allowed_values][table][0][item][label]";
        $this->getSession()->getPage()->fillField($label_element_name, 'Hello world');
        $this->assertSession()->assertWaitOnAjaxRequest();
        $this->exposeOptionMachineName(1);
        $key_element_name = "field_storage[subform][settings][allowed_values][table][0][item][key]";
        // Ensure that the machine name was generated correctly.
        $this->assertSession()->fieldValueEquals($key_element_name, 'hello_world');
        // Ensure that the machine name can be overridden with a value that includes
        // special characters.
        $this->getSession()->getPage()->fillField($key_element_name, '.hello #world');
        $this->assertSession()->assertWaitOnAjaxRequest();
        $this->getSession()->getPage()->pressButton('Save settings');
        $this->assertSession()->statusMessageContains("Saved {$this->fieldName} configuration.");
        // Ensure that the machine name was saved correctly.
        $allowed_values = FieldStorageConfig::loadByName('node', $this->fieldName)
        ->getSetting('allowed_values');
        $this->assertSame(['.hello #world'], array_keys($allowed_values));
        }
        /** /**
        * Assert the count of the allowed values rows. * Assert the count of the allowed values rows.
        * *
        ......
        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