diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 265fba9fd1f2d..c765f22ce61d4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -1054,12 +1054,8 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e ->end() ->end() ->arrayNode('not_compromised_password') - ->canBeDisabled() + ->canBeDisabled('When disabled, compromised passwords will be accepted as valid.') ->children() - ->booleanNode('enabled') - ->defaultTrue() - ->info('When disabled, compromised passwords will be accepted as valid.') - ->end() ->scalarNode('endpoint') ->defaultNull() ->info('API endpoint for the NotCompromisedPassword Validator.') diff --git a/src/Symfony/Component/Config/CHANGELOG.md b/src/Symfony/Component/Config/CHANGELOG.md index 2efbf70080de1..577fbbca53645 100644 --- a/src/Symfony/Component/Config/CHANGELOG.md +++ b/src/Symfony/Component/Config/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG --- * Add `ExprBuilder::ifFalse()` + * Add support for info on `ArrayNodeDefinition::canBeEnabled()` and `ArrayNodeDefinition::canBeDisabled()` 7.2 --- diff --git a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php index 6b75ba137a806..0f2245dfcb5b4 100644 --- a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +++ b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php @@ -239,11 +239,13 @@ public function canBeUnset(bool $allow = true): static * enableableArrayNode: {enabled: false, ...} # The config is disabled * enableableArrayNode: false # The config is disabled * + * @param string|null $info A description of what happens when the node is enabled or disabled + * * @return $this */ - public function canBeEnabled(): static + public function canBeEnabled(/* ?string $info = null */): static { - $this + $node = $this ->addDefaultsIfNotSet() ->treatFalseLike(['enabled' => false]) ->treatTrueLike(['enabled' => true]) @@ -261,6 +263,11 @@ public function canBeEnabled(): static ->defaultFalse() ; + $info = 1 <= \func_num_args() ? func_get_arg(0) : null; + if ($info) { + $node->info($info); + } + return $this; } @@ -269,11 +276,13 @@ public function canBeEnabled(): static * * By default, the section is enabled. * + * @param string|null $info A description of what happens when the node is enabled or disabled + * * @return $this */ - public function canBeDisabled(): static + public function canBeDisabled(/* ?string $info = null */): static { - $this + $node = $this ->addDefaultsIfNotSet() ->treatFalseLike(['enabled' => false]) ->treatTrueLike(['enabled' => true]) @@ -283,6 +292,11 @@ public function canBeDisabled(): static ->defaultTrue() ; + $info = 1 <= \func_num_args() ? func_get_arg(0) : null; + if ($info) { + $node->info($info); + } + return $this; } diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php index ca376ea8a79df..281813a8cd0f1 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php @@ -190,6 +190,16 @@ public function testTrueEnableEnabledNode(array $expected, array $config, string ); } + public function testCanBeEnabledWithInfo() + { + $node = new ArrayNodeDefinition('root'); + $node->canBeEnabled('Some info about disabling this node'); + + $child = $this->getField($node, 'children')['enabled']; + + $this->assertEquals('Some info about disabling this node', $this->getField($child, 'attributes')['info']); + } + public function testCanBeDisabled() { $node = new ArrayNodeDefinition('root'); @@ -208,6 +218,16 @@ public function testCanBeDisabled() $this->assertTrue($this->getField($enabledNode, 'defaultValue')); } + public function testCanBeDisabledWithInfo() + { + $node = new ArrayNodeDefinition('root'); + $node->canBeDisabled('Some info about disabling this node'); + + $child = $this->getField($node, 'children')['enabled']; + + $this->assertEquals('Some info about disabling this node', $this->getField($child, 'attributes')['info']); + } + public function testIgnoreExtraKeys() { $node = new ArrayNodeDefinition('root');