Skip to content

Commit 7d50abb

Browse files
committed
Remove help field logic and enhance unit display in DurationType forms
1 parent f22e612 commit 7d50abb

4 files changed

Lines changed: 12 additions & 34 deletions

File tree

src/Form/DurationType.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -166,36 +166,6 @@ public function configureOptions(OptionsResolver $resolver): void
166166

167167
return $data;
168168
});
169-
170-
$resolver->setNormalizer('help', function (Options $options, $value) {
171-
if (null === $value) {
172-
$dotFields = ['year', 'month', 'day'];
173-
$colonFields = ['hour', 'minute', 'second'];
174-
175-
$dotFields = array_values(array_filter($dotFields, static fn ($field) => isset($options[$field]) && $options[$field]));
176-
$colonFields = array_values(array_filter($colonFields, static fn ($field) => isset($options[$field]) && $options[$field]));
177-
178-
$value = '';
179-
180-
for ($index = 0, $lastIndex = \count($dotFields); $index < $lastIndex; ++$index) {
181-
if ($index === $lastIndex - 1 && 0 === \count($colonFields)) {
182-
$value .= \sprintf('%ss', $dotFields[$index]);
183-
} else {
184-
$value .= \sprintf('%ss.', $dotFields[$index]);
185-
}
186-
}
187-
188-
for ($index = 0, $lastIndex = \count($colonFields); $index < $lastIndex; ++$index) {
189-
if ($index === $lastIndex - 1) {
190-
$value .= \sprintf('%ss', $colonFields[$index]);
191-
} else {
192-
$value .= \sprintf('%ss:', $colonFields[$index]);
193-
}
194-
}
195-
}
196-
197-
return $value;
198-
});
199169
}
200170

201171
public function getBlockPrefix(): string

templates/form/bootstrap_5_form_layout.html.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<div class="input-group">
1616
{% if units.year %}
1717
{{ form_widget(form.year) }}
18+
<span class="input-group-text">{{ 'years' }}</span>
1819
{% endif %}
1920

2021
{% if units.month %}
@@ -23,6 +24,7 @@
2324
{% endif %}
2425

2526
{{ form_widget(form.month) }}
27+
<span class="input-group-text">{{ 'months' }}</span>
2628
{% endif %}
2729

2830
{% if units.day %}
@@ -31,6 +33,7 @@
3133
{% endif %}
3234

3335
{{ form_widget(form.day) }}
36+
<span class="input-group-text">{{ 'days' }}</span>
3437
{% endif %}
3538

3639
{% if units.hour %}
@@ -39,6 +42,7 @@
3942
{% endif %}
4043

4144
{{ form_widget(form.hour) }}
45+
<span class="input-group-text">{{ 'hours' }}</span>
4246
{% endif %}
4347

4448
{% if units.minute %}
@@ -47,6 +51,7 @@
4751
{% endif %}
4852

4953
{{ form_widget(form.minute) }}
54+
<span class="input-group-text">{{ 'minutes' }}</span>
5055
{% endif %}
5156

5257
{% if units.second %}
@@ -55,6 +60,7 @@
5560
{% endif %}
5661

5762
{{ form_widget(form.second) }}
63+
<span class="input-group-text">{{ 'seconds' }}</span>
5864
{% endif %}
5965
</div>
6066
</div>

templates/form/form_layout.html.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<div {{ block('widget_container_attributes') }}>
1010
{% if units.year %}
1111
{{ form_widget(form.year) }}
12+
<span class="input-group-text">{{ 'years' }}</span>
1213
{% endif %}
1314

1415
{% if units.month %}
@@ -17,6 +18,7 @@
1718
{% endif %}
1819

1920
{{ form_widget(form.month) }}
21+
<span class="input-group-text">{{ 'months' }}</span>
2022
{% endif %}
2123

2224
{% if units.day %}
@@ -25,6 +27,7 @@
2527
{% endif %}
2628

2729
{{ form_widget(form.day) }}
30+
<span class="input-group-text">{{ 'days' }}</span>
2831
{% endif %}
2932

3033
{% if units.hour %}
@@ -33,6 +36,7 @@
3336
{% endif %}
3437

3538
{{ form_widget(form.hour) }}
39+
<span class="input-group-text">{{ 'hours' }}</span>
3640
{% endif %}
3741

3842
{% if units.minute %}
@@ -41,6 +45,7 @@
4145
{% endif %}
4246

4347
{{ form_widget(form.minute) }}
48+
<span class="input-group-text">{{ 'minutes' }}</span>
4449
{% endif %}
4550

4651
{% if units.second %}
@@ -49,6 +54,7 @@
4954
{% endif %}
5055

5156
{{ form_widget(form.second) }}
57+
<span class="input-group-text">{{ 'seconds' }}</span>
5258
{% endif %}
5359
</div>
5460
{%- endblock -%}

tests/Form/DurationTypeTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public function testConfigureAnotherUnit(): void
4747

4848
$this->assertTrue($form->isSynchronized());
4949
$this->assertEquals(new Second("5196852"), $form->getData()->getValue());
50-
$this->assertSame("months.hours:minutes:seconds", $view->vars['help']);
5150
}
5251

5352
public function testSubmitNull(): void
@@ -81,8 +80,6 @@ public function testWithPreData(): void
8180
'minute' => '12',
8281
'second' => null,
8382
], $view->vars['value']);
84-
85-
$this->assertSame("hours:minutes", $view->vars['help']);
8683
}
8784

8885
public function testWithNullPreData(): void
@@ -95,6 +92,5 @@ public function testWithNullPreData(): void
9592

9693
// Assert
9794
$this->assertNull($view->vars['value']);
98-
$this->assertSame("hours:minutes", $view->vars['help']);
9995
}
10096
}

0 commit comments

Comments
 (0)