Skip to content

Commit ae96c70

Browse files
authored
Merge pull request #412 from FriendsOfCake/feat/help-text
Simplify HTML for help text block.
2 parents 54a2961 + 495c731 commit ae96c70

31 files changed

+358
-363
lines changed

src/View/Helper/FormHelper.php

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class FormHelper extends CoreFormHelper
141141
'label' =>
142142
'<label{{attrs}}>{{text}}{{tooltip}}</label>',
143143
'help' =>
144-
'<small{{attrs}}>{{content}}</small>',
144+
'<div{{attrs}}>{{content}}</div>',
145145
'tooltip' =>
146146
'<span data-bs-toggle="tooltip" title="{{content}}" class="bi bi-info-circle-fill"></span>',
147147
'formGroupFloatingLabel' =>
@@ -980,36 +980,31 @@ protected function _placeholderOptions(string $fieldName, array $options): array
980980
*/
981981
protected function _helpOptions(string $fieldName, array $options): array
982982
{
983-
if ($options['help']) {
984-
if (!is_array($options['help'])) {
985-
$options['help'] = [
986-
'content' => $options['help'],
987-
];
988-
}
983+
if ($options['help'] === null) {
984+
return $options;
985+
}
989986

990-
if (!isset($options['help']['id'])) {
991-
$options['help']['id'] = $this->_domId($fieldName . '-help');
992-
}
987+
if (!is_array($options['help'])) {
988+
$options['help'] = [
989+
'content' => $options['help'],
990+
];
991+
}
993992

994-
$helpClasses = [];
995-
if ($this->_align === static::ALIGN_INLINE) {
996-
$helpClasses[] = 'visually-hidden';
997-
} else {
998-
$helpClasses[] = 'd-block';
999-
}
993+
if (!isset($options['help']['id'])) {
994+
$options['help']['id'] = $this->_domId($fieldName . '-help');
995+
}
1000996

1001-
$helpClasses[] = 'form-text';
1002-
if ($this->_align !== static::ALIGN_INLINE) {
1003-
$helpClasses[] = 'text-muted';
1004-
}
997+
$helpClasses = ['form-text'];
998+
if ($this->_align === static::ALIGN_INLINE) {
999+
$helpClasses[] = 'visually-hidden';
1000+
}
10051001

1006-
$options['help'] = $this->injectClasses($helpClasses, $options['help']);
1002+
$options['help'] = $this->injectClasses($helpClasses, $options['help']);
10071003

1008-
$options['help'] = $this->templater()->format('help', [
1009-
'content' => $options['help']['content'],
1010-
'attrs' => $this->templater()->formatAttributes($options['help'], ['content']),
1011-
]);
1012-
}
1004+
$options['help'] = $this->templater()->format('help', [
1005+
'content' => $options['help']['content'],
1006+
'attrs' => $this->templater()->formatAttributes($options['help'], ['content']),
1007+
]);
10131008

10141009
return $options;
10151010
}

tests/TestCase/View/Helper/FormHelper/DefaultAlign/CheckboxControlTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ public function testDefaultAlignCheckboxControlWithHelp()
157157
['label' => ['class' => 'form-check-label', 'for' => 'users']],
158158
'Users',
159159
'/label',
160-
['small' => ['id' => 'users-help', 'class' => 'd-block form-text text-muted']],
160+
['div' => ['id' => 'users-help', 'class' => 'form-text']],
161161
'Help text',
162-
'/small',
162+
'/div',
163163
'/div',
164164
];
165165
$this->assertHtml($expected, $result);
@@ -196,13 +196,13 @@ public function testDefaultAlignCheckboxControlWithHelpOptions()
196196
['label' => ['class' => 'form-check-label', 'for' => 'users']],
197197
'Users',
198198
'/label',
199-
['small' => [
199+
['div' => [
200200
'id' => 'custom-help',
201201
'foo' => 'bar',
202-
'class' => 'help-class d-block form-text text-muted',
202+
'class' => 'help-class form-text',
203203
]],
204204
'Help text',
205-
'/small',
205+
'/div',
206206
'/div',
207207
];
208208
$this->assertHtml($expected, $result);
@@ -347,9 +347,9 @@ public function testDefaultAlignCheckboxControlWithErrorAndHelp()
347347
['div' => ['id' => 'users-error', 'class' => 'ms-0 invalid-feedback']],
348348
'error message',
349349
'/div',
350-
['small' => ['id' => 'users-help', 'class' => 'd-block form-text text-muted']],
350+
['div' => ['id' => 'users-help', 'class' => 'form-text']],
351351
'Help text',
352-
'/small',
352+
'/div',
353353
'/div',
354354
];
355355
$this->assertHtml($expected, $result);
@@ -394,13 +394,13 @@ public function testDefaultAlignCheckboxControlWithErrorAndHelpAndOptions()
394394
['div' => ['id' => 'users-error', 'class' => 'ms-0 invalid-feedback']],
395395
'error message',
396396
'/div',
397-
['small' => [
397+
['div' => [
398398
'id' => 'custom-help',
399399
'foo' => 'bar',
400-
'class' => 'help-class d-block form-text text-muted',
400+
'class' => 'help-class form-text',
401401
]],
402402
'Help text',
403-
'/small',
403+
'/div',
404404
'/div',
405405
];
406406
$this->assertHtml($expected, $result);
@@ -750,9 +750,9 @@ public function testDefaultAlignCheckboxControlInlineWithHelp()
750750
['label' => ['class' => 'form-check-label', 'for' => 'users']],
751751
'Users',
752752
'/label',
753-
['small' => ['id' => 'users-help','class' => 'd-block form-text text-muted']],
753+
['div' => ['id' => 'users-help','class' => 'form-text']],
754754
'Help text',
755-
'/small',
755+
'/div',
756756
'/div',
757757
];
758758
$this->assertHtml($expected, $result);
@@ -790,13 +790,13 @@ public function testDefaultAlignCheckboxControlInlineWithHelpOptions()
790790
['label' => ['class' => 'form-check-label', 'for' => 'users']],
791791
'Users',
792792
'/label',
793-
['small' => [
793+
['div' => [
794794
'id' => 'custom-help',
795795
'foo' => 'bar',
796-
'class' => 'help-class d-block form-text text-muted',
796+
'class' => 'help-class form-text',
797797
]],
798798
'Help text',
799-
'/small',
799+
'/div',
800800
'/div',
801801
];
802802
$this->assertHtml($expected, $result);

tests/TestCase/View/Helper/FormHelper/DefaultAlign/ColorControlTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ public function testDefaultAlignColorControlWithHelp()
133133
'aria-describedby' => 'color-help',
134134
'value' => '#ffffff',
135135
],
136-
['small' => ['id' => 'color-help', 'class' => 'd-block form-text text-muted']],
136+
['div' => ['id' => 'color-help', 'class' => 'form-text']],
137137
'Help text',
138-
'/small',
138+
'/div',
139139
'/div',
140140
];
141141
$this->assertHtml($expected, $result);
@@ -168,13 +168,13 @@ public function testDefaultAlignColorControlWithHelpOptions()
168168
'aria-describedby' => 'custom-help',
169169
'value' => '#ffffff',
170170
],
171-
['small' => [
171+
['div' => [
172172
'id' => 'custom-help',
173173
'foo' => 'bar',
174-
'class' => 'help-class d-block form-text text-muted',
174+
'class' => 'help-class form-text',
175175
]],
176176
'Help text',
177-
'/small',
177+
'/div',
178178
'/div',
179179
];
180180
$this->assertHtml($expected, $result);
@@ -300,9 +300,9 @@ public function testDefaultAlignColorControlWithErrorAndHelp()
300300
['div' => ['id' => 'color-error', 'class' => 'ms-0 invalid-feedback']],
301301
'error message',
302302
'/div',
303-
['small' => ['id' => 'color-help', 'class' => 'd-block form-text text-muted']],
303+
['div' => ['id' => 'color-help', 'class' => 'form-text']],
304304
'Help text',
305-
'/small',
305+
'/div',
306306
'/div',
307307
];
308308
$this->assertHtml($expected, $result);
@@ -342,13 +342,13 @@ public function testDefaultAlignColorControlWithErrorAndHelpOptions()
342342
['div' => ['id' => 'color-error', 'class' => 'ms-0 invalid-feedback']],
343343
'error message',
344344
'/div',
345-
['small' => [
345+
['div' => [
346346
'id' => 'custom-help',
347347
'foo' => 'bar',
348-
'class' => 'help-class d-block form-text text-muted',
348+
'class' => 'help-class form-text',
349349
]],
350350
'Help text',
351-
'/small',
351+
'/div',
352352
'/div',
353353
];
354354
$this->assertHtml($expected, $result);

tests/TestCase/View/Helper/FormHelper/DefaultAlign/DateTimeControlTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ public function testDefaultAlignDateTimeControlWithHelp()
159159
'step' => '1',
160160
'value' => date('H:i:s', $now),
161161
],
162-
['small' => ['id' => 'created-help', 'class' => 'd-block form-text text-muted']],
162+
['div' => ['id' => 'created-help', 'class' => 'form-text']],
163163
'Help text',
164-
'/small',
164+
'/div',
165165
'/div',
166166
];
167167
$this->assertHtml($expected, $result);
@@ -197,13 +197,13 @@ public function testDefaultAlignDateTimeControlWithHelpOptions()
197197
'step' => '1',
198198
'value' => date('H:i:s', $now),
199199
],
200-
['small' => [
200+
['div' => [
201201
'id' => 'custom-help',
202202
'foo' => 'bar',
203-
'class' => 'help-class d-block form-text text-muted',
203+
'class' => 'help-class form-text',
204204
]],
205205
'Help text',
206-
'/small',
206+
'/div',
207207
'/div',
208208
];
209209
$this->assertHtml($expected, $result);
@@ -346,9 +346,9 @@ public function testDefaultAlignDateTimeControlWithErrorAndHelp()
346346
['div' => ['id' => 'created-error', 'class' => 'ms-0 invalid-feedback']],
347347
'error message',
348348
'/div',
349-
['small' => ['id' => 'created-help', 'class' => 'd-block form-text text-muted']],
349+
['div' => ['id' => 'created-help', 'class' => 'form-text']],
350350
'Help text',
351-
'/small',
351+
'/div',
352352
'/div',
353353
];
354354
$this->assertHtml($expected, $result);
@@ -393,13 +393,13 @@ public function testDefaultAlignDateTimeControlWithErrorAndHelpOptions()
393393
['div' => ['id' => 'created-error', 'class' => 'ms-0 invalid-feedback']],
394394
'error message',
395395
'/div',
396-
['small' => [
396+
['div' => [
397397
'id' => 'custom-help',
398398
'foo' => 'bar',
399-
'class' => 'help-class d-block form-text text-muted',
399+
'class' => 'help-class form-text',
400400
]],
401401
'Help text',
402-
'/small',
402+
'/div',
403403
'/div',
404404
];
405405
$this->assertHtml($expected, $result);

tests/TestCase/View/Helper/FormHelper/DefaultAlign/FileControlTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ public function testDefaultAlignFileControlWithHelp()
127127
'class' => 'form-control',
128128
'aria-describedby' => 'file-help',
129129
]],
130-
['small' => ['id' => 'file-help', 'class' => 'd-block form-text text-muted']],
130+
['div' => ['id' => 'file-help', 'class' => 'form-text']],
131131
'Help text',
132-
'/small',
132+
'/div',
133133
'/div',
134134
];
135135
$this->assertHtml($expected, $result);
@@ -160,13 +160,13 @@ public function testDefaultAlignFileControlWithHelpOptions()
160160
'class' => 'form-control',
161161
'aria-describedby' => 'custom-help',
162162
]],
163-
['small' => [
163+
['div' => [
164164
'id' => 'custom-help',
165165
'foo' => 'bar',
166-
'class' => 'help-class d-block form-text text-muted',
166+
'class' => 'help-class form-text',
167167
]],
168168
'Help text',
169-
'/small',
169+
'/div',
170170
'/div',
171171
];
172172
$this->assertHtml($expected, $result);
@@ -284,9 +284,9 @@ public function testDefaultAlignFileControlWithErrorAndHelp()
284284
['div' => ['id' => 'file-error', 'class' => 'ms-0 invalid-feedback']],
285285
'error message',
286286
'/div',
287-
['small' => ['id' => 'file-help', 'class' => 'd-block form-text text-muted']],
287+
['div' => ['id' => 'file-help', 'class' => 'form-text']],
288288
'Help text',
289-
'/small',
289+
'/div',
290290
'/div',
291291
];
292292
$this->assertHtml($expected, $result);
@@ -324,13 +324,13 @@ public function testDefaultAlignFileControlWithErrorAndHelpOptions()
324324
['div' => ['id' => 'file-error', 'class' => 'ms-0 invalid-feedback']],
325325
'error message',
326326
'/div',
327-
['small' => [
327+
['div' => [
328328
'id' => 'custom-help',
329329
'foo' => 'bar',
330-
'class' => 'help-class d-block form-text text-muted',
330+
'class' => 'help-class form-text',
331331
]],
332332
'Help text',
333-
'/small',
333+
'/div',
334334
'/div',
335335
];
336336
$this->assertHtml($expected, $result);

0 commit comments

Comments
 (0)