-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Notifier] Use Importance level to set flash message type #45047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Notifier] Use Importance level to set flash message type #45047
Conversation
Hey! I think @jschaedl has recently worked with this code. Maybe they can help review this? Cheers! Carsonbot |
Can you please add a test case to cover this? |
Currently a Flash message with type "notification" is created. After this PR, the type would be either "urgent", "high", "medium" or "low". Worst case scenario is that the styling of the flash message is missing, because the class name is changed (the type is normally used to define the alert styling via CSS). I'm not sure if this is an acceptable trade-off? But for me at least, having the Browser Channel only be able to create flash messages of a single type is quite limiting. I will add a test once we decide if this is worth pursuing or not. |
Would using |
Yes, great idea - then the CSS class is still there for legacy implementations, and the user can take advantage of the new feature should they want to. I'll update the PR and add the tests ASAP. |
I've seen cases where only one type of flash mesages where retrieved to show on a page, in that case this would means this changes will make the flash message never show up which could be an annoying BC break. |
Sure, I can understand that, but it's definitely an edge case, and also if someone did implement this, for this change to have an effect they would also have to be generating the flash messages via the Notifier component, which I guess is not that many, seeing as most will likely still be dispatching flash messages from controller actions. The current state of the PR is that notifications now have a "type" of e.g. Is there any way we can keep both behaviours for now? Maybe with some service configuration? Or we could bump this forward until we can define it as a BC break? |
Instead, can we inject an Users who want to change this mapping can then implement their own, and simply override the service configuration to inject theirs instead of the default. This would allow the existing behaviour to be preserved, whilst also providing a flexible override for users who need it. If people think this is a better approach, please let me know and I'll create a PR (should this be a separate PR or should I update this one?). |
As explained, this is indeed a BC break. So, your interface approach is a nice way to solve the issue IMHO. You can update the code in this PR as it cannot be merged as is anyway. |
I have implemented the mapper as suggested. Nothing too controversial I hope, except that I've also included an additional implementation of the mapper for the Bootstrap CSS framework. We could provide implementations for the same CSS frameworks that are supported by the Form component Twig themes. Let me know if this should be a separate PR or to simply remove it, or of course to add the other implementations. |
src/Symfony/Component/Notifier/Exception/FlashMessageMappingException.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/FlashMessage/AbstractFlashMessageImportanceMapper.php
Outdated
Show resolved
Hide resolved
Can you have a look at the tests as some look broken because of the changes implemented in this PR (see Tests (8.1, low-deps) )? |
src/Symfony/Component/Notifier/Exception/FlashMessageMappingException.php
Outdated
Show resolved
Hide resolved
I see errors such as
These are because I am mocking the session with |
I've just fixed it by adding the missing dep in composer.json. |
Instead of hard-coding the flash message type, set the flash message type based on the "importance" level of the notification.
Thank you @benr77. |
Instead of hard-coding the flash message type, set the flash message type based on the "importance" level of the notification.