-
Notifications
You must be signed in to change notification settings - Fork 183
Added an optional flashmessage listener #183
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
Conversation
Resources/config/config.xml
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this definition to a new file, flash.xml, and only include it from the Extension if flash messages are to be shown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change the service to add a .default to its id, and alias the default service like most of the other services in this bundle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think making the id of the listener configurable is really useful. If they want a different listener, they should disable the built-in one and register their own listener IMO. We cannot add a tag for external services in the DI extension, so it would require adding a compiler pass to handle this configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing to note, I don't need to set that tag anymore since now the file don't get included. when it's not enabled by the config
The old way.. check if service is wanted => get definition ->addtag(kernel.event_subscriber)
The new way: include the file which has the tag already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Miliooo yeah, but it means that passign a custom service id will not replace the listener (to register your own service as listener, you have to tag it, not to pass it as id here, it simply cannot work). So the broken config key should be removed
|
It may be worth it for you to run php-cs-fixer over pull requests before sending them, alternatively if you use phpstorm, you can set it up to use phpcs to analyse your files for errors based on the PSR2 standard which lets you see errors inside the IDE as you develop. |
|
I use NetBeans and I had setup that cs-fixer but a few days ago my system freezed when opening a project. So i had to disable that plugin. Also I had enabled some reformatting options when saving but that caused whole files to be reformatted when I saved them. Not very good when you want to do pull requests... I know phpstorm is like the standard now so maybe it's time to consider switching. Anyways I'll try to get this things sorted before doing more pull requests, it saves everyone problems. Not sure how easy it will be to fix this though. I'll try to edit your remarks by hand for now... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be enabled for consistency with Symfony nodes. As of 2.3, there is even 2 shortcut methods for array nodes: canBeEnabled() and canBeDisabled(), which handle the call to addDefaultsIfNotSet() and setting the enabled with a default value (but you cannot use them yet as the bundle still need to support 2.2)
EventListener/FlashListener.php
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think making the key configurable is really needed. As Symfony 2.1+ supports putting multiple flash messages per type, it is quite logical to use success, error and warning as type IMO instead of inventing weird ones
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or I'm doing something silly but my theme has multiple places where I want to show a flash message.
I'm not sure how I would handle that with only a flash bag that has success, error and warning. How could I know then where to show them? Personally I set the key to 'message_info'. And then in my layout i check for message_info flashes on the messenger pages. So then I can show them in the right place and I know they are 'message flashes' not other ones...
But I agree for most it would be overkill... or again maybe I do something wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can solve this by extending the listener in your own app and overriding the functions that actually add flashes. Maybe move it to a getKey method which can be overridden.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing space between if ()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This occurs in a few places
|
Regarding the configurable service id, I requested it primarily for consistency with the bundle as it stands. It does seem a bit strange for an event listener though. I still want the user to be able to configure the class of the listener, rather than forcing them to override the entire service definition (or define their own). If you can change the class of the listener service definition to a parameter and remove the .default/alias that'd be good. |
|
Thanks for all the feedback. I implemented that parameter solution, and refactored that key so now it's a requirement. If there are more updates needed I'll fix them tomorrow. Also we should document this. But I think @merk knows which structure he wants there. My main language isn't english either but I'll give it a try if you want me to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this curly brace should be on the previous line
|
@stof Regarding ->canBeEnabled(), obviously this is a 2.3 specific feature. How do you feel about bumping the requirement? Maybe leave the enabled config as it is for 1.2 of this bundle, and I'll mark 2.0(or 3.0) as needing symfony >=2.3? |
|
@merk Yeah, as I said, |
|
I updated the config reference and added a link to Not sure if you want me to implement this in the current layout... |
|
I also added a new config test file. Since there was no test file included I made one based on Unless you want me to change some stuff I think this commit is done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please rename the property to containerBuilder. It will be more readable
|
This is a good idea. I will think about it for the next version. I close this as it's old, but please tell me if you want to work on this @Miliooo. |
This adds an optional flash eventlistener, which shows flashes to the user when they do certain actions.
What's included:
The current supported actions are:
How to enable
Todos
Credits
The code is based on https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/EventListener/FlashListener.php