Skip to content

Commit a760b37

Browse files
committed
bug #1148 Fix missing double dash in namespaced Stimulus outlets (Greg 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
2 parents 5e5a512 + 621171c commit a760b37

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/StimulusBundle/src/Dto/StimulusAttributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function addController(string $controllerName, array $controllerValues =
5858
}
5959

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

6363
$this->attributes['data-'.$controllerName.'-'.$outlet.'-outlet'] = $selector;
6464
}

src/StimulusBundle/tests/Twig/StimulusTwigExtensionTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ public static function provideRenderStimulusController(): iterable
119119
'expectedString' => 'data-controller="my-controller" data-my-controller-other-controller-outlet=".target"',
120120
'expectedArray' => ['data-controller' => 'my-controller', 'data-my-controller-other-controller-outlet' => '.target'],
121121
];
122+
123+
yield 'short-single-controller-no-data-with-namespaced-outlet' => [
124+
'controllerName' => 'my-controller',
125+
'controllerValues' => [],
126+
'controllerClasses' => [],
127+
'controllerOutlets' => ['namespaced--other-controller' => '.target'],
128+
'expectedString' => 'data-controller="my-controller" data-my-controller-namespaced--other-controller-outlet=".target"',
129+
'expectedArray' => ['data-controller' => 'my-controller', 'data-my-controller-namespaced--other-controller-outlet' => '.target'],
130+
];
122131
}
123132

124133
public function testAppendStimulusController(): void

0 commit comments

Comments
 (0)