From d12bc8ce0bfe1044a6ca98760b53ac0b4735fc25 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Thu, 22 Feb 2024 17:49:14 +0100 Subject: [PATCH] Fix flash messages merge, rename some variables --- .../default/elements/js/messages.js.twig | 38 ++++++++++-------- .../elements/messages_inline.html.twig | 40 +++++++++++-------- 2 files changed, 45 insertions(+), 33 deletions(-) diff --git a/galette/templates/default/elements/js/messages.js.twig b/galette/templates/default/elements/js/messages.js.twig index e6823b0cb..e1c9ca8b4 100644 --- a/galette/templates/default/elements/js/messages.js.twig +++ b/galette/templates/default/elements/js/messages.js.twig @@ -14,14 +14,15 @@ $('.message.with-transition') ; {# Let's see if there are success messages to show #} -{% set successes = flash.getMessage('success_detected') %} +{% set success = flash.getMessage('success_detected') ?? [] %} +{% set success = success|merge(flash.getMessage('success') ?? []) %} {% if success_detected is defined and success_detected is iterable %} - {% for s in success_detected %} - {% set successes = successes|merge([s]) %} + {% for entry in success_detected %} + {% set success = success|merge([entry]) %} {% endfor %} {% endif %} -{% if successes is iterable and successes|length > 0 %} - {% for success in successes %} +{% if success is iterable and success|length > 0 %} + {% for entry in success %} $('body') .toast({ displayTime: 'auto', @@ -30,7 +31,7 @@ $('.message.with-transition') showProgress: 'bottom', closeIcon: true, position: 'top attached', - message: '{{ success|e('js') }}', + message: '{{ entry|e('js') }}', showIcon: 'check circle outline', class: 'success' }) @@ -39,18 +40,20 @@ $('.message.with-transition') {% endif %} {# Let's see if there are info messages to show #} -{% set info = flash.getMessage('info_detected') ?? []|merge(flash.getMessage('info') ?? []) %} +{% set info = flash.getMessage('info_detected') ?? [] %} +{% set info = info|merge(flash.getMessage('info') ?? []) %} {% if info_detected is defined and info_detected is iterable %} - {% for i in info_detected %} - {% set info = info|merge([i]) %} + {% for entry in info_detected %} + {% set info = info|merge([entry]) %} {% endfor %} {% endif %} {% if info is iterable and info|length > 0 %} - {% for i in info %} + {% for entry in info %} {% set info_title = '' %} - {% if i is iterable %} - {% set info_title = i.title %} - {% set i = i.message %} + {% set info_message = entry %} + {% if entry is iterable %} + {% set info_title = entry.title %} + {% set info_message = entry.message %} {% endif %} $('body') .toast({ @@ -61,7 +64,7 @@ $('.message.with-transition') closeIcon: true, position: 'top attached', title: '{{ info_title|e('js') }}', - message: '{{ i|e('js') }}', + message: '{{ info_message|e('js') }}', showIcon: 'info', class: 'info' }) @@ -78,7 +81,9 @@ $('.message.with-transition') {% endif %} {# Let's see if there are error messages to show #} -{% set errors = flash.getMessage('error_detected') ?? []|merge(flash.getMessage('error') ?? [])|merge(loginfaults ?? []) %} +{% set errors = flash.getMessage('error_detected') ?? [] %} +{% set errors = errors|merge(flash.getMessage('error') ?? []) %} +{% set errors = errors|merge(loginfaults ?? []) %} {% if error_detected is defined and error_detected is iterable %} {% for e in error_detected %} {% set errors = errors|merge([e]) %} @@ -100,7 +105,8 @@ $('.message.with-transition') {% endif %} {# Let's see if there are warning messages to show #} -{% set warnings = flash.getMessage('warning_detected') ?? []|merge(flash.getMessage('warning') ?? []) %} +{% set warnings = flash.getMessage('warning_detected') ?? [] %} +{% set warnings = warnings|merge(flash.getMessage('warning') ?? []) %} {% if warning_detected is defined and warning_detected is iterable %} {% for w in warning_detected %} {% set warnings = warnings|merge([w]) %} diff --git a/galette/templates/default/elements/messages_inline.html.twig b/galette/templates/default/elements/messages_inline.html.twig index 409828fba..a078ae270 100644 --- a/galette/templates/default/elements/messages_inline.html.twig +++ b/galette/templates/default/elements/messages_inline.html.twig @@ -7,7 +7,9 @@ {% endif %} {# Let's see if there are error messages to show #} -{% set errors = flash.getMessage('error_detected') ?? []|merge(flash.getMessage('error') ?? [])|merge(loginfaults ?? []) %} +{% set errors = flash.getMessage('error_detected') ?? [] %} +{% set errors = errors|merge(flash.getMessage('error') ?? []) %} +{% set errors = errors|merge(loginfaults ?? []) %} {% if error_detected is defined and error_detected is iterable %} {% for e in error_detected %} {% set errors = errors|merge([e]) %} @@ -36,7 +38,8 @@ {% endif %} {# Let's see if there are warning messages to show #} -{% set warnings = flash.getMessage('warning_detected') ?? []|merge(flash.getMessage('warning') ?? []) %} +{% set warnings = flash.getMessage('warning_detected') ?? [] %} +{% set warnings = warnings|merge(flash.getMessage('warning') ?? []) %} {% if warning_detected is defined and warning_detected is iterable %} {% for w in warning_detected %} {% set warnings = warnings|merge([w]) %} @@ -65,27 +68,28 @@ {% endif %} {# Let's see if there are success messages to show #} -{% set successs = flash.getMessage('success_detected') ?? []|merge(flash.getMessage('success') ?? []) %} +{% set success = flash.getMessage('success_detected') ?? [] %} +{% set success = success|merge(flash.getMessage('success') ?? []) %} {% if success_detected is defined and success_detected is iterable %} - {% for s in success_detected %} - {% set successs = successs|merge([s]) %} + {% for entry in success_detected %} + {% set success = success|merge([entry]) %} {% endfor %} {% endif %} -{% if successs is iterable and successs|length > 0 %} +{% if success is iterable and success|length > 0 %}