Skip to content

Commit d27916b

Browse files
committed
bug #1193 [StimulusBundle] feat: normalize parameters names given to twig helper 'stimulus_action' (norival)
This PR was merged into the 2.x branch. Discussion ---------- [StimulusBundle] feat: normalize parameters names given to twig helper 'stimulus_action' | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Tickets | NA | License | MIT This allows giving a parameter name as 'myParam', and it will be printed as 'data-controller-name-my-param-param', which will be interpreted as 'myParam' by the Stimulus controller. Commits ------- ed02dad [StimulusBundle] feat: normalize parameters names given to twig helper 'stimulus_action()'
2 parents 46d0b68 + ed02dad commit d27916b

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/StimulusBundle/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# CHANGELOG
22

3+
## 2.13.0
4+
5+
- Normalize parameters names given to twig helper 'stimulus_action()'.
6+
**BC Break**: previously, parameters given in camelCase (eg.
7+
`bigCrocodile`) were incorrectly registered by the controller as
8+
flatcase (`event.params.bigcrocodile`). This was fixed, which means
9+
they are now correctly registered as camelCase
10+
(`event.params.bigCrocodile`).
11+
312
## 2.10.0
413

514
- Handle Stimulus outlets

src/StimulusBundle/src/Dto/StimulusAttributes.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ public function addAction(string $controllerName, string $actionName, string $ev
7979
];
8080

8181
foreach ($parameters as $name => $value) {
82-
$this->attributes['data-'.$controllerName.'-'.$name.'-param'] = $this->getFormattedValue($value);
82+
$key = $this->normalizeKeyName($name);
83+
84+
$this->attributes['data-'.$controllerName.'-'.$key.'-param'] = $this->getFormattedValue($value);
8385
}
8486
}
8587

src/StimulusBundle/tests/Twig/StimulusTwigExtensionTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ public static function provideRenderStimulusAction(): iterable
199199
'expectedString' => 'data-action="click->symfony--ux-dropzone--dropzone#onClick"',
200200
'expectedArray' => ['data-action' => 'click->symfony--ux-dropzone--dropzone#onClick'],
201201
];
202+
203+
yield 'normalize-name, with normalized parameters names' => [
204+
'controllerName' => 'my-controller',
205+
'actionName' => 'onClick',
206+
'eventName' => null,
207+
'parameters' => ['boolParam' => true, 'intParam' => 4, 'stringParam' => 'test'],
208+
'expectedString' => 'data-action="onClick"',
209+
'expectedString' => 'data-action="my-controller#onClick" data-my-controller-bool-param-param="true" data-my-controller-int-param-param="4" data-my-controller-string-param-param="test"',
210+
'expectedArray' => ['data-action' => 'my-controller#onClick', 'data-my-controller-bool-param-param' => 'true', 'data-my-controller-int-param-param' => '4', 'data-my-controller-string-param-param' => 'test'],
211+
];
202212
}
203213

204214
public function testAppendStimulusAction(): void

0 commit comments

Comments
 (0)