Skip to content

Commit 68cd260

Browse files
committed
minor #14161 Added support for using the "{{ label }}" placeholder in constraint messages (a-menshchikov)
This PR was squashed before being merged into the master branch. Discussion ---------- Added support for using the "{{ label }}" placeholder in constraint messages Docs for symfony/symfony#35338 Commits ------- e298929 Added support for using the "{{ label }}" placeholder in constraint messages
2 parents 3c9e289 + e298929 commit 68cd260

32 files changed

+175
-0
lines changed

components/form.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,11 @@ and the errors will display next to the fields on error.
728728
For a list of all of the built-in validation constraints, see
729729
:doc:`/reference/constraints`.
730730

731+
.. versionadded:: 5.2
732+
733+
Constraint message can contains ``{{ label }}`` placeholder that will be replaced
734+
by corresponding form field label (in view of ``label_format`` option).
735+
731736
Accessing Form Errors
732737
~~~~~~~~~~~~~~~~~~~~~
733738

forms.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,11 @@ corresponding errors printed out with the form. Read the
548548
:doc:`Symfony validation documentation </validation>` to learn more about this
549549
powerful feature.
550550

551+
.. versionadded:: 5.2
552+
553+
Constraint message can contains ``{{ label }}`` placeholder that will be replaced
554+
by corresponding form field label (in view of ``label_format`` option).
555+
551556
Other Common Form Features
552557
--------------------------
553558

reference/constraints/Blank.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ You can use the following parameters in this message:
102102
Parameter Description
103103
=============== ==============================================================
104104
``{{ value }}`` The current (invalid) value
105+
``{{ label }}`` Corresponding form field label
105106
=============== ==============================================================
106107

108+
.. versionadded:: 5.2
109+
110+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
111+
107112
.. include:: /reference/constraints/_payload-option.rst.inc

reference/constraints/CardScheme.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,13 @@ You can use the following parameters in this message:
112112
Parameter Description
113113
=============== ==============================================================
114114
``{{ value }}`` The current (invalid) value
115+
``{{ label }}`` Corresponding form field label
115116
=============== ==============================================================
116117

118+
.. versionadded:: 5.2
119+
120+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
121+
117122
.. include:: /reference/constraints/_payload-option.rst.inc
118123

119124
schemes

reference/constraints/Choice.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,11 @@ You can use the following parameters in this message:
392392
Parameter Description
393393
=============== ==============================================================
394394
``{{ value }}`` The current (invalid) value
395+
``{{ label }}`` Corresponding form field label
395396
=============== ==============================================================
396397

398+
.. versionadded:: 5.2
399+
400+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
401+
397402
.. include:: /reference/constraints/_payload-option.rst.inc

reference/constraints/Currency.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,13 @@ You can use the following parameters in this message:
9494
Parameter Description
9595
=============== ==============================================================
9696
``{{ value }}`` The current (invalid) value
97+
``{{ label }}`` Corresponding form field label
9798
=============== ==============================================================
9899

100+
.. versionadded:: 5.2
101+
102+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
103+
99104
.. include:: /reference/constraints/_payload-option.rst.inc
100105

101106
.. _`3-letter ISO 4217`: https://en.wikipedia.org/wiki/ISO_4217

reference/constraints/Date.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ You can use the following parameters in this message:
9898
Parameter Description
9999
=============== ==============================================================
100100
``{{ value }}`` The current (invalid) value
101+
``{{ label }}`` Corresponding form field label
101102
=============== ==============================================================
102103

104+
.. versionadded:: 5.2
105+
106+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
107+
103108
.. include:: /reference/constraints/_payload-option.rst.inc

reference/constraints/DateTime.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ You can use the following parameters in this message:
107107
Parameter Description
108108
=============== ==============================================================
109109
``{{ value }}`` The current (invalid) value
110+
``{{ label }}`` Corresponding form field label
110111
=============== ==============================================================
111112

113+
.. versionadded:: 5.2
114+
115+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
116+
112117
.. include:: /reference/constraints/_payload-option.rst.inc

reference/constraints/Email.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,13 @@ You can use the following parameters in this message:
101101
Parameter Description
102102
=============== ==============================================================
103103
``{{ value }}`` The current (invalid) value
104+
``{{ label }}`` Corresponding form field label
104105
=============== ==============================================================
105106

107+
.. versionadded:: 5.2
108+
109+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
110+
106111
mode
107112
~~~~
108113

reference/constraints/Expression.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,13 @@ You can use the following parameters in this message:
260260
Parameter Description
261261
=============== ==============================================================
262262
``{{ value }}`` The current (invalid) value
263+
``{{ label }}`` Corresponding form field label
263264
=============== ==============================================================
264265

266+
.. versionadded:: 5.2
267+
268+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
269+
265270
.. include:: /reference/constraints/_payload-option.rst.inc
266271

267272
values

reference/constraints/Hostname.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,13 @@ You can use the following parameters in this message:
110110
Parameter Description
111111
=============== ==============================================================
112112
``{{ value }}`` The current (invalid) value
113+
``{{ label }}`` Corresponding form field label
113114
=============== ==============================================================
114115

116+
.. versionadded:: 5.2
117+
118+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
119+
115120
.. include:: /reference/constraints/_payload-option.rst.inc
116121

117122
``requireTld``

reference/constraints/Iban.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,13 @@ You can use the following parameters in this message:
108108
Parameter Description
109109
=============== ==============================================================
110110
``{{ value }}`` The current (invalid) value
111+
``{{ label }}`` Corresponding form field label
111112
=============== ==============================================================
112113

114+
.. versionadded:: 5.2
115+
116+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
117+
113118
.. include:: /reference/constraints/_payload-option.rst.inc
114119

115120
.. _`International Bank Account Number (IBAN)`: https://en.wikipedia.org/wiki/International_Bank_Account_Number

reference/constraints/Ip.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,13 @@ You can use the following parameters in this message:
9595
Parameter Description
9696
=============== ==============================================================
9797
``{{ value }}`` The current (invalid) value
98+
``{{ label }}`` Corresponding form field label
9899
=============== ==============================================================
99100

101+
.. versionadded:: 5.2
102+
103+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
104+
100105
.. include:: /reference/constraints/_normalizer-option.rst.inc
101106

102107
.. include:: /reference/constraints/_payload-option.rst.inc

reference/constraints/IsFalse.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ You can use the following parameters in this message:
125125
Parameter Description
126126
=============== ==============================================================
127127
``{{ value }}`` The current (invalid) value
128+
``{{ label }}`` Corresponding form field label
128129
=============== ==============================================================
129130

131+
.. versionadded:: 5.2
132+
133+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
134+
130135
.. include:: /reference/constraints/_payload-option.rst.inc

reference/constraints/IsNull.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ You can use the following parameters in this message:
9696
Parameter Description
9797
=============== ==============================================================
9898
``{{ value }}`` The current (invalid) value
99+
``{{ label }}`` Corresponding form field label
99100
=============== ==============================================================
100101

102+
.. versionadded:: 5.2
103+
104+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
105+
101106
.. include:: /reference/constraints/_payload-option.rst.inc

reference/constraints/IsTrue.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ You can use the following parameters in this message:
129129
Parameter Description
130130
=============== ==============================================================
131131
``{{ value }}`` The current (invalid) value
132+
``{{ label }}`` Corresponding form field label
132133
=============== ==============================================================
133134

135+
.. versionadded:: 5.2
136+
137+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
138+
134139
.. include:: /reference/constraints/_payload-option.rst.inc

reference/constraints/Isbn.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,13 @@ You can use the following parameters in this message:
109109
Parameter Description
110110
=============== ==============================================================
111111
``{{ value }}`` The current (invalid) value
112+
``{{ label }}`` Corresponding form field label
112113
=============== ==============================================================
113114

115+
.. versionadded:: 5.2
116+
117+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
118+
114119
.. include:: /reference/constraints/_groups-option.rst.inc
115120

116121
isbn10Message
@@ -127,8 +132,13 @@ You can use the following parameters in this message:
127132
Parameter Description
128133
=============== ==============================================================
129134
``{{ value }}`` The current (invalid) value
135+
``{{ label }}`` Corresponding form field label
130136
=============== ==============================================================
131137

138+
.. versionadded:: 5.2
139+
140+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
141+
132142
isbn13Message
133143
~~~~~~~~~~~~~
134144

@@ -143,8 +153,13 @@ You can use the following parameters in this message:
143153
Parameter Description
144154
=============== ==============================================================
145155
``{{ value }}`` The current (invalid) value
156+
``{{ label }}`` Corresponding form field label
146157
=============== ==============================================================
147158

159+
.. versionadded:: 5.2
160+
161+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
162+
148163
message
149164
~~~~~~~
150165

@@ -159,8 +174,13 @@ You can use the following parameters in this message:
159174
Parameter Description
160175
=============== ==============================================================
161176
``{{ value }}`` The current (invalid) value
177+
``{{ label }}`` Corresponding form field label
162178
=============== ==============================================================
163179

180+
.. versionadded:: 5.2
181+
182+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
183+
164184
.. include:: /reference/constraints/_payload-option.rst.inc
165185

166186
type

reference/constraints/Isin.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,13 @@ You can use the following parameters in this message:
9292
Parameter Description
9393
=============== ==============================================================
9494
``{{ value }}`` The current (invalid) value
95+
``{{ label }}`` Corresponding form field label
9596
=============== ==============================================================
9697

98+
.. versionadded:: 5.2
99+
100+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
101+
97102
.. include:: /reference/constraints/_payload-option.rst.inc
98103

99104
.. _`International Securities Identification Number (ISIN)`: https://en.wikipedia.org/wiki/International_Securities_Identification_Number

reference/constraints/Issn.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,13 @@ You can use the following parameters in this message:
102102
Parameter Description
103103
=============== ==============================================================
104104
``{{ value }}`` The current (invalid) value
105+
``{{ label }}`` Corresponding form field label
105106
=============== ==============================================================
106107

108+
.. versionadded:: 5.2
109+
110+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
111+
107112
.. include:: /reference/constraints/_payload-option.rst.inc
108113

109114
requireHyphen

reference/constraints/Language.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,13 @@ You can use the following parameters in this message:
106106
Parameter Description
107107
=============== ==============================================================
108108
``{{ value }}`` The current (invalid) value
109+
``{{ label }}`` Corresponding form field label
109110
=============== ==============================================================
110111

112+
.. versionadded:: 5.2
113+
114+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
115+
111116
.. include:: /reference/constraints/_payload-option.rst.inc
112117

113118
.. _`ISO 639-1`: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes

reference/constraints/Locale.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,13 @@ You can use the following parameters in this message:
107107
Parameter Description
108108
=============== ==============================================================
109109
``{{ value }}`` The current (invalid) value
110+
``{{ label }}`` Corresponding form field label
110111
=============== ==============================================================
111112

113+
.. versionadded:: 5.2
114+
115+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
116+
112117
.. include:: /reference/constraints/_payload-option.rst.inc
113118

114119
.. _`ICU format locale IDs`: http://userguide.icu-project.org/locale

reference/constraints/Luhn.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,13 @@ You can use the following parameters in this message:
101101
Parameter Description
102102
=============== ==============================================================
103103
``{{ value }}`` The current (invalid) value
104+
``{{ label }}`` Corresponding form field label
104105
=============== ==============================================================
105106

107+
.. versionadded:: 5.2
108+
109+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
110+
106111
.. include:: /reference/constraints/_payload-option.rst.inc
107112

108113
.. _`Luhn algorithm`: https://en.wikipedia.org/wiki/Luhn_algorithm

reference/constraints/NotBlank.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,13 @@ You can use the following parameters in this message:
105105
Parameter Description
106106
=============== ==============================================================
107107
``{{ value }}`` The current (invalid) value
108+
``{{ label }}`` Corresponding form field label
108109
=============== ==============================================================
109110

111+
.. versionadded:: 5.2
112+
113+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
114+
110115
.. include:: /reference/constraints/_normalizer-option.rst.inc
111116

112117
.. include:: /reference/constraints/_payload-option.rst.inc

reference/constraints/NotNull.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ You can use the following parameters in this message:
9494
Parameter Description
9595
=============== ==============================================================
9696
``{{ value }}`` The current (invalid) value
97+
``{{ label }}`` Corresponding form field label
9798
=============== ==============================================================
9899

100+
.. versionadded:: 5.2
101+
102+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
103+
99104
.. include:: /reference/constraints/_payload-option.rst.inc

reference/constraints/Range.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,13 @@ You can use the following parameters in this message:
330330
Parameter Description
331331
=============== ==============================================================
332332
``{{ value }}`` The current (invalid) value
333+
``{{ label }}`` Corresponding form field label
333334
=============== ==============================================================
334335

336+
.. versionadded:: 5.2
337+
338+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
339+
335340
max
336341
~~~
337342

reference/constraints/Regex.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,13 @@ You can use the following parameters in this message:
275275
Parameter Description
276276
=============== ==============================================================
277277
``{{ value }}`` The current (invalid) value
278+
``{{ label }}`` Corresponding form field label
278279
=============== ==============================================================
279280

281+
.. versionadded:: 5.2
282+
283+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
284+
280285
pattern
281286
~~~~~~~
282287

reference/constraints/Time.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ You can use the following parameters in this message:
101101
Parameter Description
102102
=============== ==============================================================
103103
``{{ value }}`` The current (invalid) value
104+
``{{ label }}`` Corresponding form field label
104105
=============== ==============================================================
105106

107+
.. versionadded:: 5.2
108+
109+
The ``{{ label }}`` parameter was introduced in Symfony 5.2.
110+
106111
.. include:: /reference/constraints/_payload-option.rst.inc

0 commit comments

Comments
 (0)