symfony/stimulus-bundle
Symfony bundle that integrates Stimulus with Symfony and Symfony UX. Adds Twig stimulus_* helpers for controllers/actions/targets, supports AssetMapper, and provides a service to build Stimulus data attributes for use in templates and services.
stimulus_controller, stimulus_action, stimulus_target) to embed Stimulus behavior directly in templates, reducing boilerplate and improving maintainability.| Risk | Severity | Mitigation Strategy |
|---|---|---|
| Symfony Version Lock-in | Medium | Requires Symfony 7.4+ (v3.0.0) or 6.4+ (v2.34.0). Audit app compatibility early. |
| AssetMapper Dependency | High | Test with excluded_patterns in config/packages/asset_mapper.yaml to avoid breaking existing assets. |
| Twig Template Refactoring | Medium | Audit templates for onclick handlers or inline JS; replace with stimulus_* functions. |
| Stimulus Learning Curve | Low | Provide internal docs/workshops on Stimulus controllers, actions, and targets. |
| Debugging Complexity | Medium | Standardize on Symfony Profiler + Browser DevTools for Stimulus action debugging. |
| PHP 8.4+ Requirement (v3.0.0) | High | Upgrade PHP if using v3.0.0; otherwise, stick to v2.x for PHP 8.1+ support. |
| TypeScript Controllers | Low | Ensure build tools (e.g., Webpack Encore) support TypeScript if using TS controllers. |
Symfony Ecosystem Alignment:
Migration Strategy:
Team Readiness:
Performance Impact:
Long-Term Viability:
Alternatives:
excluded_patterns to avoid conflicts with existing assets.stimulus_* functions. Templates must be refactored to use declarative Stimulus attributes.Preparation Phase:
Core Integration:
composer require symfony/stimulus-bundle
# config/packages/asset_mapper.yaml
framework:
asset_mapper:
excluded_patterns:
- '*/controllers.json' # Updated in v2.33+
config/bundles.php:
return [
// ...
Symfony\UX\StimulusBundle\StimulusBundle::class => ['all' => true],
];
Template Migration:
onclick) with Twig functions:
{# Before: #}
<button onclick="showModal()">Open</button>
{# After: #}
<button {{ stimulus_controller('modal') }} data-action="click->modal#show">Open</button>
stimulus_action for dynamic parameters:
{{ stimulus_action('modal#show', { id: 'user-123' }) }}
Controller Development:
assets/controllers/ (or a custom path):
// assets/controllers/modal_controller.js
import { Controller } from '@hotwired/stimulus';
export default class extends Controller {
show() {
this.element.showModal();
}
}
Advanced Integration (Optional):
{{ stimulus_data({ user: app.service('user').getCurrentUser() }) }}
Testing & Optimization:
@stimulus/test).ux_controller_link_tags in v3.0.0).| Component | Compatibility Notes |
|---|---|
| Symfony Versions | v2.x: 6.4+; v3.0.0: 7.4+. Downgrade if using older versions. |
| PHP Versions | v2.x: 8.1+; v3.0.0: 8.4+. Upgrade PHP if needed. |
| AssetMapper | v3.0.0+ requires AssetMapper ≥6.4. Use excluded_patterns to avoid conflicts. |
| Webpack Encore | Supported but may need ES Modules config for Stimulus controllers. |
| Twig | Mandatory for stimulus_* functions. No legacy Twig support in v3.0.0. |
| Symfony UX | Native integration with Turbo, Mercure, Dropzone. |
| TypeScript | Supported but requires build tool configuration (e.g., |
How can I help you explore Laravel packages today?