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
FRAMEWORK method addFlash definition in AbstractController differs from underlying FlashBag->add #34645
Comments
more or less duplicates #28991 :) AFAIK we should loosen Ultimately users are in control, and responsible if e.g messages are valid payload/serializable/etc. Perhaps, given the type is mixed at the API level, simply renaming |
…addFlash() (ThomasLandauer) This PR was merged into the 3.4 branch. Discussion ---------- [FrameworkBundle] fix type annotation on ControllerTrait::addFlash() | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Fix #28991 Fix #34645 | License | MIT | Doc PR | not yet, see below Removing `string` type-hint of $message at addFlash() Closes #28991 and #34645 Reasons: * `addFlash()` is just a convenience shortcut for `FlashBagInterface::add()` which doesn't have the type hint: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php#L28 . So removing it here improves consistency. * #28991 (comment) is a valid use case for having an object as `$message`. * Twig doesn't have any rendering helpers for the `message`, see https://symfony.com/doc/current/controller.html#flash-messages . And since users have to take care of displaying the `message` themselves, there's no reason to force a string upon them. * This isn't a real new feature, but it isn't a bugfix either ;-) * I didn't update `src/**/CHANGELOG.md` yet. * I'm not sure if it's necessary to update the docs. Maybe a short note https://symfony.com/doc/current/controller.html#flash-messages ? Commits ------- dfb4614 Update AbstractController.php
Removing `string` type-hint of $message at addFlash() Closes symfony/symfony#28991 and symfony/symfony#34645 Reasons: * `addFlash()` is just a convenience shortcut for `FlashBagInterface::add()` which doesn't have the type hint: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php#L28 . So removing it here improves consistency. * symfony/symfony#28991 (comment) is a valid use case for having an object as `$message`. * Twig doesn't have any rendering helpers for the `message`, see https://symfony.com/doc/current/controller.html#flash-messages . And since users have to take care of displaying the `message` themselves, there's no reason to force a string upon them.
Thanks |
Symfony version(s) affected: 4.4.0 - 5.0
Description
The addFlash method in the AbstractController (5.0) and the ControllerTrait (4.4) limit the definition of a message to a string, but the Flashbag itself does not limit the message by type at all.
The addFlash in the controller method is:
and the Flashbag method is
I have been using the Flashbag with a Message as an array [message, params, domain] and twig just looks for an iterable message and renders appropriately with translation.
How to reproduce
Any controller code that uses addFlash must use a string ONLY for the message.
Possible Solution
Remove the restriction on the addFlash so that addFlash and FlashBag->add are defined equally.
Additional context
I would vote for allowing the addFlash to not be limited to only strings. An example of my current flash renderer in TWIG is:
Appreciate any feedback!
Craig
The text was updated successfully, but these errors were encountered: