pentiminax / ux-sweet-alert
SweetAlert2 integration for Symfony
Installs: 1 771
Dependents: 0
Suggesters: 0
Security: 0
Stars: 20
Watchers: 1
Forks: 1
Open Issues: 0
Type:symfony-bundle
pkg:composer/pentiminax/ux-sweet-alert
Requires
- php: >=8.2
- symfony/config: ^7.0
- symfony/dependency-injection: ^7.0
- symfony/http-kernel: ^7.0
- symfony/stimulus-bundle: ^2.22
- symfony/ux-live-component: ^2.26
- symfony/ux-twig-component: ^2.26
- twig/twig: ^3.8
Requires (Dev)
- phpstan/phpstan: ^2.1.12
- phpunit/phpunit: ^11.5.17
- symfony/framework-bundle: ^7.0
- symfony/phpunit-bridge: ^7.0
- symfony/twig-bundle: ^7.0
- symfony/var-dumper: ^7.0
Conflicts
- symfony/flex: <1.13
- dev-main
- v0.7.5
- v0.7.4
- v0.7.3
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.0
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- dev-codex/update-alertextension-for-turbo-compatibility
- dev-codex/fix-alertmanager-and-toastmanager-state-issue
- dev-fix/confirm-button-services
- dev-feat/html-description
This package is auto-updated.
Last update: 2025-10-13 21:02:05 UTC
README
UX SweetAlert is a Symfony bundle that integrates the SweetAlert2 library into your Symfony applications. It provides PHP helpers and a Stimulus controller to easily display alerts and toast notifications.
Requirements
- PHP 8.2 or higher
- Symfony StimulusBundle
- Composer
Installation
Install the library via Composer:
composer require pentiminax/ux-sweet-alert
Basic usage
To automatically display toasts and alerts in your templates, add the following Twig function in your base.html.twig (or the layout file):
{{ ux_sweet_alert_scripts() }}
Alerts
Inject the AlertManagerInterface and use the helper methods to create alerts:
use Pentiminax\UX\SweetAlert\AlertManagerInterface; #[Route('/', name: 'app_homepage')] public function index(AlertManagerInterface $alertManager): Response { $alertManager->success( title: 'Update Successful', text: 'Your settings have been saved.' ); return $this->redirectToRoute('dashboard'); }
Toasts
Inject the ToastManagerInterface
service and
create toasts:
use Pentiminax\UX\SweetAlert\Enum\Position; use Pentiminax\UX\SweetAlert\ToastManagerInterface; class HomeController extends AbstractController { #[Route('/', name: 'app_homepage')] public function index(ToastManagerInterface $toastManager): Response { $toastManager->success( title: 'title', text: 'text', position: Position::TOP_END, showConfirmButton: false, timer: 3000, timerProgressBar: true ); return $this->render('home/index.html.twig'); } }