Events
The PWA Bundle uses Symfony's PSR-14 Event Dispatcher system to allow customization of the manifest generation process. You can listen to these events to modify the manifest before or after compilation.
Available Events
The bundle dispatches two main events during manifest generation:
PreManifestCompileEvent
Dispatched before the manifest is compiled. Use this event to:
Add dynamic data to the manifest
Modify manifest properties based on runtime conditions
Inject user-specific or request-specific information
PostManifestCompileEvent
Dispatched after the manifest is compiled. Use this event to:
Validate the compiled manifest
Add additional processing
Log manifest details
Perform cleanup operations
Basic Event Listener
Here's how to create an event listener for both events:
Use Cases
Adding Dynamic Data
Inject dynamic information like user preferences or runtime configuration:
Multi-Locale Support
Adapt the manifest for different locales:
Environment-Based Configuration
Modify manifest based on the environment (dev/staging/prod):
Logging and Validation
Validate manifest data and log issues:
Adding Analytics Tracking
Include analytics parameters in URLs:
Event API Reference
PreManifestCompileEvent
Methods:
getManifest(): Returns theManifestDTO object (read/write)getRequest(): Returns the currentRequestobject (read-only)
Usage:
PostManifestCompileEvent
Methods:
getData(): Returns the compiled manifest as an array (read-only)getRequest(): Returns the currentRequestobject (read-only)
Usage:
Best Practices
Use PreCompile for modifications: Modify the manifest object in
PreManifestCompileEventUse PostCompile for validation: Check the compiled data in
PostManifestCompileEventKeep listeners focused: Each listener should handle one specific concern
Avoid heavy operations: Events are dispatched on every manifest request
Test thoroughly: Ensure your modifications don't break manifest validity
Handle errors gracefully: Don't throw exceptions that could break manifest generation
Debugging Events
Enable logging to see when events are dispatched:
Then log in your listener:
Last updated
Was this helpful?