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

Issue #3401186 by Wim Leers, alexpott: Follow-up for #3382510: Throw...

Issue #3401186 by Wim Leers, alexpott: Follow-up for #3382510: Throw \LogicException when >1 #config_target in the same form targets the same property path

(cherry picked from commit 40084a52b0329dd9ce70e9d992a90cb64e4924d2)
parent 1221e7e5
Branches
Tags
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 #49826 passed
Pipeline: drupal

#49827

    ......@@ -136,6 +136,14 @@ public function storeConfigKeyToFormElementMap(array $element, FormStateInterfac
    $target = ConfigTarget::fromString($target);
    }
    foreach ($target->propertyPaths as $property_path) {
    if (isset($map[$target->configName][$property_path])) {
    throw new \LogicException(sprintf('Two #config_targets both target "%s" in the "%s" config: `%s` and `%s`.',
    $property_path,
    $target->configName,
    '$form[\'' . implode("']['", $map[$target->configName][$property_path]) . '\']',
    '$form[\'' . implode("']['", $element['#array_parents']) . '\']',
    ));
    }
    $map[$target->configName][$property_path] = $element['#array_parents'];
    }
    $form_state->set(static::CONFIG_KEY_TO_FORM_ELEMENT_MAP, $map);
    ......
    ......@@ -3,9 +3,14 @@
    namespace Drupal\Tests\Core\Form;
    use Drupal\Core\Config\Config;
    use Drupal\Core\Config\ConfigFactoryInterface;
    use Drupal\Core\Config\TypedConfigManagerInterface;
    use Drupal\Core\Form\ConfigFormBase;
    use Drupal\Core\Form\ConfigTarget;
    use Drupal\Core\Form\ToConfig;
    use Drupal\Core\Form\FormStateInterface;
    use Drupal\Core\Form\FormState;
    use Drupal\Core\Form\RedundantEditableConfigNamesTrait;
    use Drupal\Tests\UnitTestCase;
    use Prophecy\Argument;
    ......@@ -15,6 +20,45 @@
    */
    class ConfigTargetTest extends UnitTestCase {
    /**
    * @covers \Drupal\Core\Form\ConfigFormBase::storeConfigKeyToFormElementMap
    */
    public function testDuplicateTargetsNotAllowed(): void {
    $form = [
    'test' => [
    '#type' => 'text',
    '#default_value' => 'A test',
    '#config_target' => new ConfigTarget('system.site', 'admin_compact_mode', 'intval', 'boolval'),
    '#name' => 'test',
    '#array_parents' => ['test'],
    ],
    'duplicate' => [
    '#type' => 'text',
    '#config_target' => new ConfigTarget('system.site', 'admin_compact_mode', 'intval', 'boolval'),
    '#name' => 'duplicate',
    '#array_parents' => ['duplicate'],
    ],
    ];
    $test_form = new class(
    $this->prophesize(ConfigFactoryInterface::class)->reveal(),
    $this->prophesize(TypedConfigManagerInterface::class)->reveal(),
    ) extends ConfigFormBase {
    use RedundantEditableConfigNamesTrait;
    public function getFormId() {
    return 'test';
    }
    };
    $form_state = new FormState();
    $test_form->storeConfigKeyToFormElementMap($form['test'], $form_state);
    $this->expectException(\LogicException::class);
    $this->expectExceptionMessage('Two #config_targets both target "admin_compact_mode" in the "system.site" config: `$form[\'test\']` and `$form[\'duplicate\']`.');
    $test_form->storeConfigKeyToFormElementMap($form['duplicate'], $form_state);
    }
    /**
    * @covers ::fromForm
    * @covers ::fromString
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment