Q | A |
---|
Branch? | 6.3 for features |
Bug fix? | no |
New feature? | yes |
Deprecations? | no |
License | MIT |
Doc PR | symfony/symfony-docs#... |
So this change is coming from aPR 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
{% block base_flashbags_checkout %} <div> {% for type, messages in app.flashes %} {% sw_include '@Storefront/storefront/utilities/alert.html.twig' with { type: type, list: messages } %} {% endfor %} </div>{% endblock %}
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:
{% extends ... %}{% block other_block %} {% set myPluginFlashes = app.flashes %} {% set myPluginErrorMessages in myPluginFlashes.error|default([]) %} {% for error in myPluginErrorMessages %} {# Do some fancy mobile notification popup style stuff #} {% endfor %}{% endblock %}{% block base_flashbags_checkout %} <div> {% for type, messages in myPluginFlashes %} {% sw_include '@Storefront/storefront/utilities/alert.html.twig' with { type: type, list: messages } %} {% endfor %} </div>{% endblock %}
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:
{% extends ... %}{% block other_block %} {% for error in app.flashes('error') %} {# Do some fancy mobile notification popup style stuff #} {% endfor %}{% endblock %}
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 followhttps://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry
symfony/symfony-docs#...
- Always add tests and ensure they pass. (ok, yes I assumed to have to write a test)
So this change is coming from aPR 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 followhttps://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry
symfony/symfony-docs#...