Skip to content

Commit d25e71e

Browse files
committed
"Improve normalization logic in Configuration for type handling and validation."
1 parent 33f7d41 commit d25e71e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/TwigHooks/src/DependencyInjection/Configuration.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ private function addHooksConfiguration(ArrayNodeDefinition $rootNode): void
6969
->arrayPrototype()
7070
->beforeNormalization()
7171
->always(function ($v) {
72+
$isTypeDefined = isset($v['type']);
7273
$isComponentDefined = isset($v['component']);
7374
$isTemplateDefined = isset($v['template']);
7475
$isDisabled = isset($v['enabled']) && $v['enabled'] === false;
@@ -77,6 +78,10 @@ private function addHooksConfiguration(ArrayNodeDefinition $rootNode): void
7778
return $v;
7879
}
7980

81+
if (true === $isTypeDefined) {
82+
return $v;
83+
}
84+
8085
$v['type'] = match (true) {
8186
$isDisabled => 'disabled',
8287
$isComponentDefined => 'component',
@@ -89,6 +94,16 @@ private function addHooksConfiguration(ArrayNodeDefinition $rootNode): void
8994
->end()
9095
->validate()
9196
->always(static function ($v) {
97+
$type = $v['type'] ?? null;
98+
if ('template' === $type) {
99+
unset($v['component']);
100+
$v['props'] = [];
101+
}
102+
103+
if ('component' === $type) {
104+
unset($v['template']);
105+
}
106+
92107
$component = $v['component'] ?? null;
93108
$template = $v['template'] ?? null;
94109
$enabled = $v['enabled'] ?? true;

0 commit comments

Comments
 (0)