[HttpFoundation] Feature: Introduce flashbag cache to Twig AppVariable #49042
+176
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
So this change is coming from a PR at Shopware which shall help intercompatibility of flashbag usage in a multi vendor application when using plugins trying to access the flashbag content.
In Shopware you have a section in the checkout that renders flashbag entries containing error/warning/info messages:
https://github.com/shopware/platform/blob/d6c853ca3b6b167d61d70e6329f4fcface5c5245/src/Storefront/Resources/views/storefront/page/checkout/_page.html.twig#L12-L18
This happens not as early in the template as some like to want. The content is also not stored in a variable which makes it difficult to re-access the content.
So now I want to display the content in a different form for mobile users. For that I have to move it somewhere else, store it in a variable and override the block and use a stored variation of the flashbag:
Now imagine every Shopware extension does it this way. This will break easily and will not work well together.
In a perfect world I could just write:
My thoughts/journey:
So therefore I just cache it in the flashbag. But wait. The flashbag is made to forget. But it has a peek method. I could use the peek instead of the get in the AppVariable. But then the flashbag never forgets what has been used. I could forward the flashbag peek to the AppVariable as new method. But then everyone has to use "the right method". To difficult to migrate to, still likely to break. Ok, then I make a cache in the AppVariable so it can forget what it was asked but keep it for the rest of the rendering.
I am not sure whether this is a feature or a bugfix. It does not really feel like a bugfix as it contains a breaking change. But really does not feel like a feature either.
TODOs I was not aware of at the time of writing:
please update src/**/CHANGELOG.md files --- Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry
symfony/symfony-docs#...