make sure that minute_increment is not zero (#2860)

This commit is contained in:
Kevin Papst
2021-10-16 13:38:28 +02:00
committed by GitHub
parent e2be5b401c
commit fb265ed732
3 changed files with 17 additions and 6 deletions

View File

@@ -354,10 +354,10 @@ final class SystemConfigurationController extends AbstractController
(new Configuration())
->setName('timesheet.time_increment')
->setType(MinuteIncrementType::class)
->setOptions(['deactivate' => false])
->setOptions(['deactivate' => false, 'max_one_hour' => true])
->setTranslationDomain('system-configuration')
->setConstraints([
new GreaterThanOrEqual(['value' => 1])
new Range(['min' => 1, 'max' => 60])
]),
(new Configuration())
->setName('timesheet.duration_increment')

View File

@@ -55,13 +55,20 @@ class DateTimePickerType extends AbstractType
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['attr'] = array_merge($view->vars['attr'], [
$attr = array_merge($view->vars['attr'], [
'data-datetimepicker' => 'on',
'autocomplete' => 'off',
'placeholder' => strtoupper($options['format']),
'data-format' => $options['format_picker'],
'data-time-picker-increment' => $options['time_increment'],
]);
if ($options['time_increment'] !== null) {
if ($options['time_increment'] >= 1) {
$attr['data-time-picker-increment'] = $options['time_increment'];
}
}
$view->vars['attr'] = $attr;
}
/**

View File

@@ -26,6 +26,7 @@ class MinuteIncrementType extends AbstractType
{
$resolver->setDefaults([
'deactivate' => true,
'max_one_hour' => false,
]);
$resolver->setDefault('choices', function (Options $options) {
@@ -47,8 +48,11 @@ class MinuteIncrementType extends AbstractType
$choices['30'] = '30';
$choices['45'] = '45';
$choices['60'] = '60';
$choices['90'] = '90';
$choices['120'] = '120';
if (!$options['max_one_hour']) {
$choices['90'] = '90';
$choices['120'] = '120';
}
return $choices;
});