Skip to content

Commit

Permalink
bug #1148 Fix missing double dash in namespaced Stimulus outlets (Gre…
Browse files Browse the repository at this point in the history
…g Berger)

This PR was merged into the 2.x branch.

Discussion
----------

Fix missing double dash in namespaced Stimulus outlets

| Q             | A
| ------------- | ---
| Bug fix?     |  yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Tickets       |  /
| License       | MIT

In `StimulusTwigExtension`, namespaced (ie: in sub directories) stimulus controllers didn't work as the regex in `StimulusAttribute::normalizeKeyName` removes the double-dash needed to mark
namespace separations.

As the outlet value is the name of a controller, I suggest to use `normalizeControllerName` from the same class, instead.

Commits
-------

621171c Fix missing double dash in namespaced Stimulus outlets
  • Loading branch information
weaverryan committed Oct 2, 2023
2 parents 5e5a512 + 621171c commit a760b37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/StimulusBundle/src/Dto/StimulusAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function addController(string $controllerName, array $controllerValues =
}

foreach ($controllerOutlets as $outlet => $selector) {
$outlet = $this->normalizeKeyName($outlet);
$outlet = $this->normalizeControllerName($outlet);

$this->attributes['data-'.$controllerName.'-'.$outlet.'-outlet'] = $selector;
}
Expand Down
9 changes: 9 additions & 0 deletions src/StimulusBundle/tests/Twig/StimulusTwigExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ public static function provideRenderStimulusController(): iterable
'expectedString' => 'data-controller="my-controller" data-my-controller-other-controller-outlet=".target"',
'expectedArray' => ['data-controller' => 'my-controller', 'data-my-controller-other-controller-outlet' => '.target'],
];

yield 'short-single-controller-no-data-with-namespaced-outlet' => [
'controllerName' => 'my-controller',
'controllerValues' => [],
'controllerClasses' => [],
'controllerOutlets' => ['namespaced--other-controller' => '.target'],
'expectedString' => 'data-controller="my-controller" data-my-controller-namespaced--other-controller-outlet=".target"',
'expectedArray' => ['data-controller' => 'my-controller', 'data-my-controller-namespaced--other-controller-outlet' => '.target'],
];
}

public function testAppendStimulusController(): void
Expand Down

0 comments on commit a760b37

Please sign in to comment.