Skip to content

Navigation Menu

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

Appearance settings

FlashBag peekMultiple() method #49659

Copy link
Copy link
Open
alexmerlin/symfony
#1
alexmerlin/symfony#1
@jontjs

Description

@jontjs
Issue body actions

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.