Skip to content

[StimulusBundle] feat: normalize parameters names given to twig helper 'stimulus_action' #1193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/StimulusBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# CHANGELOG

## 2.13.0

- Normalize parameters names given to twig helper 'stimulus_action()'.
**BC Break**: previously, parameters given in camelCase (eg.
`bigCrocodile`) were incorrectly registered by the controller as
flatcase (`event.params.bigcrocodile`). This was fixed, which means
they are now correctly registered as camelCase
(`event.params.bigCrocodile`).

## 2.10.0

- Handle Stimulus outlets
Expand Down
4 changes: 3 additions & 1 deletion src/StimulusBundle/src/Dto/StimulusAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ public function addAction(string $controllerName, string $actionName, string $ev
];

foreach ($parameters as $name => $value) {
$this->attributes['data-'.$controllerName.'-'.$name.'-param'] = $this->getFormattedValue($value);
$key = $this->normalizeKeyName($name);

$this->attributes['data-'.$controllerName.'-'.$key.'-param'] = $this->getFormattedValue($value);
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/StimulusBundle/tests/Twig/StimulusTwigExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ public static function provideRenderStimulusAction(): iterable
'expectedString' => 'data-action="click->symfony--ux-dropzone--dropzone#onClick"',
'expectedArray' => ['data-action' => 'click->symfony--ux-dropzone--dropzone#onClick'],
];

yield 'normalize-name, with normalized parameters names' => [
'controllerName' => 'my-controller',
'actionName' => 'onClick',
'eventName' => null,
'parameters' => ['boolParam' => true, 'intParam' => 4, 'stringParam' => 'test'],
'expectedString' => 'data-action="onClick"',
'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"',
'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'],
];
}

public function testAppendStimulusAction(): void
Expand Down