Skip to content

Commit dde0826

Browse files
committed
Simple implementation of event name normalizer
1 parent 1b80015 commit dde0826

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/StimulusBundle/src/Dto/StimulusAttributes.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,20 @@ private function normalizeControllerName(string $controllerName): string
236236
return preg_replace('/^@/', '', str_replace('_', '-', str_replace('/', '--', $controllerName)));
237237
}
238238

239+
/**
240+
* Normalize a Stimulus controller's action event name
241+
*
242+
* @see https://stimulus.hotwired.dev/reference/actions
243+
*/
244+
private function normalizeEventName(?string $eventName): ?string
245+
{
246+
if (null === $eventName) {
247+
return null;
248+
}
249+
250+
return preg_replace_callback('/^.+(?=:)/', fn (array $matches): string => $this->normalizeControllerName($matches[0]), $eventName);
251+
}
252+
239253
/**
240254
* Normalize a Stimulus Value API key into its HTML equivalent ("kebab case").
241255
* Backport features from symfony/string.

0 commit comments

Comments
 (0)