Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpFoundation] Feature: Introduce flashbag cache to Twig AppVariable#49042

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
JoshuaBehrens wants to merge1 commit intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromJoshuaBehrens:patch-1

Conversation

JoshuaBehrens
Copy link
Contributor

QA
Branch?6.3 for features
Bug fix?no
New feature?yes
Deprecations?no
LicenseMIT
Doc PRsymfony/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)

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "6.3" but it seems your PR description refers to branch "6.3 for features".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@stof
Copy link
Member

this is definitely a feature, not a bugfix

@carsonbotcarsonbot changed the titleFeature: Introduce flashbag cache to Twig AppVariable[HttpFoundation] Feature: Introduce flashbag cache to Twig AppVariableJan 22, 2023
@nicolas-grekasnicolas-grekas modified the milestones:6.3,6.4May 23, 2023
@nicolas-grekasnicolas-grekas modified the milestones:6.4,7.1Nov 15, 2023
@xabbuhxabbuh modified the milestones:7.1,7.2May 15, 2024
@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@GromNaNGromNaNGromNaN left review comments

@stofstofstof left review comments

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

7 participants
@JoshuaBehrens@carsonbot@stof@GromNaN@fabpot@nicolas-grekas@xabbuh

[8]ページ先頭

©2009-2025 Movatter.jp