Alert Manager & Alert Object
AlertManagerInterface is the main entry point of the bundle. Its job is to create an Alert,
store it, and expose it to the frontend controller.
Manager methods
| Method | Purpose |
|---|---|
| success(), error(), warning(), info(), question() | Create modal alerts with a predefined icon. |
| toast() | Create a non-blocking toast notification. |
| input() | Create an alert configured by an input type object. |
| addAlert(Alert $alert) | Push a manually created alert into storage. |
| getAlerts() | Consume queued alerts, optionally converting flash messages. |
Manual alert creation
Alert::new() creates a standalone alert with an optional icon, position, and custom class array.
Alert::withDefaults() is what the manager uses internally when bundle defaults should be applied.
Selected Alert capabilities
| Category | Available methods |
|---|---|
| Buttons | withCancelButton(), withDenyButton(), withoutConfirmButton(), reverseButtons(), confirmButtonText(), cancelButtonText(), setDenyButtonText() |
| Behavior | withoutAnimation(), withoutBackdrop(), denyOutsideClick(), denyEscapeKey(), setFocusConfirm(), setDraggable(), setTopLayer() |
| Layout | position(), theme(), customClass through manager helper arguments |
| Content | html(), setFooter(), setImageUrl(), setImageAlt(), setImageHeight() |
| Input-related | input(), inputLabel(), inputPlaceholder(), inputValue(), inputAttributes(), inputOptions(), validationMessage(), returnInputValueOnDeny() |
| Callbacks | callbackUrl() |
Serialization
The Alert object implements JsonSerializable. The JSON payload sent to the frontend includes the
modal settings and, when relevant:
toast,timer, andtimerProgressBarfor toast modebackdropandallowOutsideClickfor modal modecallbackUrlwhen a backend callback was configured
Storage lifecycle
Alerts are stored in the session under the ux-sweet-alert:alerts key. getAlerts() behaves as a
consume-on-read operation: once the alerts are read for rendering, they are removed from session
storage.
Symfony queue events
The manager dispatches two Symfony events around addAlert(Alert $alert):
| Event | When it fires | Typical use |
|---|---|---|
| `BeforeAlertQueuedEvent` | Before the alert is stored in session/context. | Enrich or adjust the mutable `Alert` instance. |
| `AlertQueuedEvent` | After the alert has been stored. | Observe, log, or trigger side effects. |
Listeners receive the same Alert object that the manager persists, so changes made during
BeforeAlertQueuedEvent are reflected in storage and rendering.
use Pentiminax\UX\SweetAlert\Event\BeforeAlertQueuedEvent;
use Pentiminax\UX\SweetAlert\Enum\Theme;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
#[AsEventListener]
final class BrandAlertsListener
{
public function __invoke(BeforeAlertQueuedEvent $event): void
{
$event->getAlert()
->theme(Theme::Dark)
->withCancelButton();
}
}