Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 575eaa1

Browse files
committed
Fix some deprecations
1 parent 90f8c7b commit 575eaa1

20 files changed

Lines changed: 151 additions & 36 deletions

File tree

templates/components/ActionMenu/ActionList/Header.html.twig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
htmlAttributes = {},
66
%}
77

8-
{% if label is not empty or icon is not empty %}
8+
{# don't use 'label is not empty' here; it'll trigger deprecation messages: Method TranslatableMessage::__toString() is deprecated #}
9+
{% set has_label = label is not same as(false) and label is not null and label is not same as('') %}
10+
{% if has_label or icon is not empty %}
911
<li {{ attributes.defaults({class: 'dropdown-header'}|merge(htmlAttributes)) }}>
1012
{%- if icon %}<twig:ea:Icon {{ ...attributes.nested('icon').defaults({name: icon}) }} /> {% endif -%}
11-
{%- if label is not empty -%}<span {{ attributes.nested('label') }}>{{ renderLabelRaw ? label|raw : label }}</span>{%- endif -%}
13+
{%- if has_label -%}<span {{ attributes.nested('label') }}>{{ renderLabelRaw ? label|raw : label }}</span>{%- endif -%}
1214
</li>
1315
{% endif %}

templates/components/ActionMenu/ActionList/Item.html.twig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
{% elseif showBlankIcons %}
2828
<twig:ea:Icon name="internal:blank" />
2929
{% endif %}
30-
{% if label is not empty %}<span {{ attributes.nested('label') }}>{{ renderLabelRaw ? label|raw : label }}</span>{% endif %}
30+
{# don't use 'label is not empty' here; it'll trigger deprecation messages: Method TranslatableMessage::__toString() is deprecated #}
31+
{% set has_label = label is not same as(false) and label is not null and label is not same as('') %}
32+
{% if has_label %}<span {{ attributes.nested('label') }}>{{ renderLabelRaw ? label|raw : label }}</span>{% endif %}
3133
</a>
3234
</li>

templates/components/ActionMenu/ActionList/ItemGroup.html.twig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
{% elseif showBlankIcons or group.hasAnyActionWithIcon %}
2727
<twig:ea:Icon name="internal:blank" />
2828
{% endif %}
29-
{% if group.mainAction.label is not empty and group.mainAction.label is not same as(false) %}
29+
{# don't use 'label is not empty' here; it'll trigger deprecation messages: Method TranslatableMessage::__toString() is deprecated #}
30+
{% if group.mainAction.label is not same as(false) and group.mainAction.label is not null and group.mainAction.label is not same as('') %}
3031
<span>{{ group.mainAction.label|trans }}</span>
3132
{% endif %}
3233
</a>
@@ -36,13 +37,15 @@
3637
</div>
3738
{% else %}
3839
{# regular submenu toggle #}
40+
{# don't use 'group.label is not empty' here; it'll trigger deprecation messages: Method TranslatableMessage::__toString() is deprecated #}
41+
{% set has_group_label = group.label is not same as(false) and group.label is not null and group.label is not same as('') %}
3942
<a class="dropdown-item dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false">
4043
{% if group.icon %}
4144
<twig:ea:Icon name="{{ group.icon }}" />
4245
{% elseif showBlankIcons or group.hasAnyActionWithIcon %}
4346
<twig:ea:Icon name="internal:blank" />
4447
{% endif %}
45-
{% if group.label is not empty %}<span>{{ group.label|trans }}</span>{% endif %}
48+
{% if has_group_label is not empty %}<span>{{ group.label|trans }}</span>{% endif %}
4649
</a>
4750
{% endif %}
4851

templates/crud/detail.html.twig

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,17 @@
6868
{% endblock %}
6969

7070
{% macro render_field_contents(entity, field) %}
71+
{# don't use 'field.help is not empty' here; it'll trigger deprecation messages: Method TranslatableMessage::__toString() is deprecated #}
72+
{% set has_help = field.help is not same as(false) and field.help is not null and field.help is not same as('') %}
73+
7174
<div class="field-group {{ field.cssClass }}" {% for name, value in field.htmlAttributes %}{{ name }}="{{ value|e('html') }}" {% endfor %}>
7275
{% if field.label is same as (false) %}
7376
{# a FALSE label value means that the field doesn't even display the <label> element;
7477
use an empty string to not display a label but keep the <label> element to not mess with the layout #}
7578
{% else %}
7679
<div class="field-label">
7780
{%- set label_html_attributes -%}
78-
{%- if field.help is not empty -%}
81+
{%- if has_help -%}
7982
data-bs-toggle="tooltip" data-bs-placement="auto" data-bs-animation="false"
8083
data-bs-html="true" data-bs-custom-class="ea-detail-label-tooltip"
8184
data-bs-title="{{ field.help|trans|e('html') }}"
@@ -193,17 +196,19 @@
193196

194197
{% macro render_column_open(field) %}
195198
{% set field_icon = field.getCustomOption('icon') %}
196-
{% set column_has_title = field_icon != null or field.label != false or field.label != null or field.label != '' or field.help != null %}
199+
{# don't use 'field.label is not empty' or 'field.label != ...' here; it'll trigger deprecation messages: Method TranslatableMessage::__toString() is deprecated #}
200+
{% set has_label = field.label is not same as(false) and field.label is not null and field.label is not same as('') %}
201+
{% set column_has_title = field_icon is not null or has_label or field.help is not null %}
197202

198203
<div class="form-column {{ not column_has_title ? 'form-column-no-header' }} {{ field.cssClass }}">
199204
{% if column_has_title %}
200205
<div class="form-column-title">
201206
<div class="form-column-title-content">
202207
{% if field_icon %}<twig:ea:Icon name="{{ field_icon }}" class="form-column-icon" />{% endif %}
203-
{% if field.label %}{{ field.label|trans(domain: ea().i18n.translationDomain)|raw }}{% endif %}
208+
{% if has_label %}{{ field.label|trans(domain: ea().i18n.translationDomain)|raw }}{% endif %}
204209
</div>
205210

206-
{% if field.help %}
211+
{% if field.help is not null %}
207212
<div class="form-column-help">{{ field.help|trans(domain: ea().i18n.translationDomain)|raw }}</div>
208213
{% endif %}
209214
</div>
@@ -215,7 +220,11 @@
215220
{% endmacro %}
216221

217222
{% macro render_fieldset_open(field) %}
218-
{% set fieldset_has_header = field.label or field.getCustomOption('icon') or field.help %}
223+
{# don't use 'field.help is not empty' here; it'll trigger deprecation messages: Method TranslatableMessage::__toString() is deprecated #}
224+
{% set has_help = field.help is not same as(false) and field.help is not null and field.help is not same as('') %}
225+
{# don't use 'field.label is not empty' here; it'll trigger deprecation messages: Method TranslatableMessage::__toString() is deprecated #}
226+
{% set has_label = field.label is not same as(false) and field.label is not null and field.label is not same as('') %}
227+
{% set fieldset_has_header = has_label or field.getCustomOption('icon') or has_help %}
219228
{% set is_collapsible_option_name = constant('EasyCorp\\Bundle\\EasyAdminBundle\\Field\\FormField::OPTION_COLLAPSIBLE') %}
220229
{% set is_collapsed_option_name = constant('EasyCorp\\Bundle\\EasyAdminBundle\\Field\\FormField::OPTION_COLLAPSED') %}
221230
{% set is_collapsible = field.getCustomOption(is_collapsible_option_name) %}
@@ -224,7 +233,7 @@
224233
<div class="form-fieldset {{ not fieldset_has_header ? 'form-fieldset-no-header' }} {{ field.cssClass }}">
225234
<fieldset>
226235
{% if fieldset_has_header %}
227-
<div class="form-fieldset-header {{ is_collapsible ? 'collapsible' }} {{ field.help is not empty ? 'with-help' }}">
236+
<div class="form-fieldset-header {{ is_collapsible ? 'collapsible' }} {{ has_help ? 'with-help' }}">
228237
<div class="form-fieldset-title">
229238
{% set fieldset_title_contents %}
230239
{% if is_collapsible %}
@@ -250,7 +259,7 @@
250259
</span>
251260
{% endif %}
252261

253-
{% if field.help %}
262+
{% if has_help %}
254263
<div class="form-fieldset-help">{{ field.help|trans|raw }}</div>
255264
{% endif %}
256265
</div>

templates/crud/form_theme.html.twig

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -540,17 +540,20 @@
540540
{% block ea_form_column_open_row %}
541541
{% set field = form.vars.ea_vars.field %}
542542
{% set field_icon = field.getCustomOption('icon') %}
543-
{% set column_has_title = field_icon != null or field.label != false or field.label != null or field.label != '' or field.help != null %}
543+
{# don't use "field.label|default()" here; it'll trigger deprecation messages: Method TranslatableMessage::__toString() is deprecated #}
544+
{% set has_label = field.label is not same as(false) and field.label is not null and field.label is not same as('') %}
545+
{% set has_help = field.help is not same as(false) and field.help is not null and field.help is not same as('') %}
546+
{% set column_has_title = field_icon != null or has_label or has_help %}
544547

545548
<div class="form-column {{ not column_has_title ? 'form-column-no-header' }} {{ field.cssClass }}">
546549
{% if column_has_title %}
547550
<div class="form-column-title">
548551
<div class="form-column-title-content">
549552
{% if field_icon %}<twig:ea:Icon name="{{ field_icon }}" class="form-column-icon" />{% endif %}
550-
{% if field.label %}{{ field.label|default('')|trans(domain: ea().i18n.translationDomain)|raw }}{% endif %}
553+
{% if has_label %}{{ field.label|trans(domain: ea().i18n.translationDomain)|raw }}{% endif %}
551554
</div>
552555

553-
{% if field.help %}
556+
{% if has_help %}
554557
<div class="form-column-help">{{ field.help|trans(domain: ea().i18n.translationDomain)|raw }}</div>
555558
{% endif %}
556559
</div>
@@ -574,7 +577,10 @@
574577
{% endblock ea_form_fieldset_open_ealabel %}
575578

576579
{% block ea_form_fieldset_open_label %}
577-
<div class="form-fieldset-header {{ ea_is_collapsible ? 'collapsible' }} {{ ea_help is not empty ? 'with-help' }}">
580+
{# don't use 'ea_help is not empty' here; it'll trigger deprecation messages: Method TranslatableMessage::__toString() is deprecated #}
581+
{% set has_help = ea_help is not same as(false) and ea_help is not null and ea_help is not same as('') %}
582+
583+
<div class="form-fieldset-header {{ ea_is_collapsible ? 'collapsible' }} {{ has_help ? 'with-help' }}">
578584
<div class="form-fieldset-title">
579585
{% if ea_is_collapsible %}
580586
<a href="#content-{{ form.vars.name }}" data-bs-toggle="collapse"
@@ -588,15 +594,19 @@
588594
</span>
589595
{% endif %}
590596

591-
{% if ea_help %}
597+
{% if has_help %}
592598
<div class="form-fieldset-help">{{ ea_help|trans|raw }}</div>
593599
{% endif %}
594600
</div>
595601
</div>
596602
{% endblock ea_form_fieldset_open_label %}
597603

598604
{% block ea_form_fieldset_open_row %}
599-
{% set fieldset_has_header = form.vars.label or ea_icon or ea_help %}
605+
{# don't use 'ea_help is not empty' here; it'll trigger deprecation messages: Method TranslatableMessage::__toString() is deprecated #}
606+
{% set has_help = ea_help is not same as(false) and ea_help is not null and ea_help is not same as('') %}
607+
{# don't use 'form.vars.label is not empty' here; it'll trigger deprecation messages: Method TranslatableMessage::__toString() is deprecated #}
608+
{% set has_label = form.vars.label is not same as(false) and form.vars.label is not null and form.vars.label is not same as('') %}
609+
{% set fieldset_has_header = has_label or ea_icon or has_help %}
600610

601611
<div class="form-fieldset {{ not fieldset_has_header ? 'form-fieldset-no-header' }} {{ ea_css_class }}">
602612
<fieldset>
@@ -684,7 +694,10 @@
684694
<input type="checkbox" class="filter-checkbox" {% if field.vars.name in applied_filters %}checked{% endif %}>
685695
<a data-bs-toggle="collapse" href="#filter-content-{{ loop.index }}" aria-expanded="{{ field.vars.name in applied_filters ? 'true' : 'false' }}" aria-controls="filter-content-{{ loop.index }}"
686696
{% for name, value in field.vars.label_attr|default([]) %}{{ name }}="{{ value|e('html') }}" {% endfor %}>
687-
{{ field.vars.label|default(field.vars.name|humanize)|trans(domain: ea().i18n.translationDomain) }}
697+
{# don't use 'field.vars.label is not empty' here; it'll trigger deprecation messages: Method TranslatableMessage::__toString() is deprecated #}
698+
{% set has_filter_label = field.vars.label is not same as(false) and field.vars.label is not null and field.vars.label is not same as('') %}
699+
{% set filter_label = has_filter_label ? field.vars.label : field.vars.name|humanize %}
700+
{{ filter_label|trans(domain: ea().i18n.translationDomain) }}
688701
</a>
689702
</div>
690703
<div id="filter-content-{{ loop.index }}" class="filter-content collapse {% if field.vars.name in applied_filters %}show{% endif %}" aria-labelledby="filter-heading-{{ loop.index }}">
@@ -732,7 +745,8 @@
732745
{% endif %}
733746
<div class="custom-file">
734747
{{ form_widget(form.file, {attr: form.file.vars.attr|merge({placeholder: placeholder, title: title, 'data-files-label': filesLabel, class: 'd-none'})}) }}
735-
{{ form_label(form.file, placeholder, {label_attr: {class: 'custom-file-label'}}) }}
748+
{# don't pass 'placeholder' as the 2nd argument of form_label(); Twig calls testEmpty() on it internally, which triggers the TranslatableMessage::__toString() deprecation #}
749+
{{ form_label(form.file, null, {label: placeholder, label_attr: {class: 'custom-file-label'}}) }}
736750
</div>
737751
<div class="input-group-text">
738752
{%- if currentFiles -%}

templates/layout.html.twig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@
363363
{% block content %}
364364
<article class="content">
365365
{% block content_header_wrapper %}
366-
{% set has_help_message = (ea.crud.helpMessage ?? '') is not empty %}
366+
{% set crud_help_message = ea.crud.helpMessage ?? null %}
367+
{# don't use 'crud_help_message is not empty' here; it'll trigger deprecation messages: Method TranslatableMessage::__toString() is deprecated #}
368+
{% set has_help_message = crud_help_message is not same as(false) and crud_help_message is not null and crud_help_message is not same as('') %}
367369
<section class="content-header">
368370
{% block content_header %}
369371
<div class="content-header-title">

templates/symfony-form-themes/bootstrap_5_layout.html.twig

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,9 @@
283283
{%- if required -%}
284284
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) -%}
285285
{%- endif -%}
286-
{%- if label is not same as(false) and label is empty -%}
286+
{# don't use 'label is not empty' here; it'll trigger deprecation messages: Method TranslatableMessage::__toString() is deprecated #}
287+
{% set has_label = label is not same as(false) and label is not null and label is not same as('') %}
288+
{%- if not has_label -%}
287289
{%- if label_format is not empty -%}
288290
{%- set label = label_format|replace({
289291
'%name%': name,
@@ -322,7 +324,9 @@
322324
{%- set element = 'fieldset' -%}
323325
{%- endif -%}
324326
{%- set widget_attr = {} -%}
325-
{%- if help is not empty -%}
327+
{# don't use 'help is not empty' here; it'll trigger deprecation messages: Method TranslatableMessage::__toString() is deprecated #}
328+
{% set has_help = help is not same as(false) and help is not null and help is not same as('') %}
329+
{%- if has_help -%}
326330
{%- set widget_attr = {attr: {'aria-describedby': id ~ '_help'}} -%}
327331
{%- endif -%}
328332
{%- set row_class = row_class|default(row_attr.class|default('mb-3')|trim) -%}
@@ -364,7 +368,9 @@
364368
{#- Hack to properly display help with input group -#}
365369
{% set help_class = ' input-group-text' %}
366370
{% endif %}
367-
{%- if help is not empty -%}
371+
{# don't use 'help is not empty' here; it'll trigger deprecation messages: Method TranslatableMessage::__toString() is deprecated #}
372+
{% set has_help = help is not same as(false) and help is not null and help is not same as('') %}
373+
{%- if has_help -%}
368374
{%- set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ help_class ~ ' mb-0')|trim}) -%}
369375
{%- endif -%}
370376
{{- parent() -}}

0 commit comments

Comments
 (0)