Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e5ec28

Browse files
committed
minor #16776 [Notifier] Add docs for FlashMessageImportanceMapper (benr77)
This PR was merged into the 6.1 branch. Discussion ---------- [Notifier] Add docs for FlashMessageImportanceMapper Add missing documentation for FlashMessageImportanceMapper (#16654) Commits ------- 7e0fb3e Add docs for FlashMessageImportanceMapper
2 parents e86c1c2 + 7e0fb3e commit 9e5ec28

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

notifier.rst

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,62 @@ and
662662
:class:`Symfony\\Component\\Notifier\\Notification\\EmailNotificationInterface`
663663
also exists to modify messages sent to those channels.
664664

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+
665721
Disabling Delivery
666722
------------------
667723

0 commit comments

Comments
 (0)