|
662 | 662 | :class:`Symfony\\Component\\Notifier\\Notification\\EmailNotificationInterface`
|
663 | 663 | also exists to modify messages sent to those channels.
|
664 | 664 |
|
| 665 | +Customize Browser Notifications (Flash Messages) |
| 666 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 667 | + |
| 668 | +.. versionadded:: 6.1 |
| 669 | + |
| 670 | + Support for customizing importance levels was introduced in Symfony 6.1. |
| 671 | + |
| 672 | +The default behavior for Browser channel notifications is to add a flash |
| 673 | +message with a key of "notification". |
| 674 | + |
| 675 | +However, it may be desirable to map the importance level of the notification |
| 676 | +to the type of flash message, so that you can style the different flash |
| 677 | +messages according to their importance. |
| 678 | + |
| 679 | +This can be done by overriding the default |
| 680 | +``notifier.flash_message_importance_mapper`` service with your own implementation of |
| 681 | +:class:`Symfony\\Component\\Notifier\\FlashMessage\\FlashMessageImportanceMapperInterface` |
| 682 | +where you can provide your own "importance" to "alert level" mapping. |
| 683 | + |
| 684 | +Symfony currently provides an implementation for the Bootstrap CSS framework's |
| 685 | +typical alert levels, which you can implement immediately using: |
| 686 | + |
| 687 | +.. configuration-block:: |
| 688 | + |
| 689 | + .. code-block:: yaml |
| 690 | +
|
| 691 | + # config/services.yaml |
| 692 | + services: |
| 693 | + notifier.flash_message_importance_mapper: Symfony\Component\Notifier\FlashMessage\BootstrapFlashMessageImportanceMapper |
| 694 | +
|
| 695 | + .. code-block:: xml |
| 696 | +
|
| 697 | + <?xml version="1.0" encoding="UTF-8" ?> |
| 698 | + <container xmlns="http://symfony.com/schema/dic/services" |
| 699 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 700 | + xsi:schemaLocation="http://symfony.com/schema/dic/services |
| 701 | + https://symfony.com/schema/dic/services/services-1.0.xsd"> |
| 702 | +
|
| 703 | + <services> |
| 704 | + <service id="notifier.flash_message_importance_mapper" class="Symfony\Component\Notifier\FlashMessage\BootstrapFlashMessageImportanceMapper"/> |
| 705 | + </services> |
| 706 | + </container> |
| 707 | +
|
| 708 | + .. code-block:: php |
| 709 | +
|
| 710 | + // config/services.php |
| 711 | + namespace Symfony\Component\DependencyInjection\Loader\Configurator; |
| 712 | +
|
| 713 | + use Symfony\Component\Notifier\FlashMessage\BootstrapFlashMessageImportanceMapper; |
| 714 | +
|
| 715 | + return function(ContainerConfigurator $configurator) { |
| 716 | + $configurator->services() |
| 717 | + ->set('notifier.flash_message_importance_mapper', BootstrapFlashMessageImportanceMapper::class) |
| 718 | + ; |
| 719 | + }; |
| 720 | +
|
665 | 721 | Disabling Delivery
|
666 | 722 | ------------------
|
667 | 723 |
|
|
0 commit comments