Skip to content

FlashBag peekMultiple() method #49659

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

Open
jontjs opened this issue Mar 10, 2023 · 3 comments · May be fixed by alexmerlin/symfony#1 or #50380
Open

FlashBag peekMultiple() method #49659

jontjs opened this issue Mar 10, 2023 · 3 comments · May be fixed by alexmerlin/symfony#1 or #50380

Comments

@jontjs
Copy link
Contributor

jontjs commented Mar 10, 2023

Description

The FlashBag allows us to peek() for a SINGLE type of message, or for ALL messages, but it would be useful to peek for multiple specific types.

My use case is to check whether or not there are any messages before outputting a wrapper HTML element.

I considered extending the existing peekAll() method to take an optional argument, but a dedicated method feels "more correct".

If this sounds like a useful feature I can supply a PR.

Example

Before:

{% if app.session.flashbag.peek('error') is not empty or app.session.flashbag.peek('warning') is not empty or app.session.flashbag.peek('notice') is not empty or app.session.flashbag.peek('foo') is not empty or app.session.flashbag.peek('bar') is not empty or app.session.flashbag.peek('baz') is not empty %}
	<div class="messages-wrapper">
		{# show the messages #}
	</div>
{% endif %}

After:

{% if app.session.flashbag.peekMultiple(['error','warning','notice','foo','bar','baz']) is not empty %}
	<div class="messages-wrapper">
		{# show the messages #}
	</div>
{% endif %}

Note that I would prefer to pass a variable number of string arguments to peekMultiple() rather than an array, but I can't see how that would work in conjunction with allowing a final $default argument, as the current peek() method does.

@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@carsonbot
Copy link

Just a quick reminder to make a comment on this. If I don't hear anything I'll close this.

@jontjs
Copy link
Contributor Author

jontjs commented Oct 2, 2023

I would still like to see this feature, and there appears to be a PR at #50380.

@carsonbot carsonbot removed the Stalled label Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants