Skip to content

Commit 2b57477

Browse files
committed
fix(timefield): assign a default value
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent 08c06ed commit 2b57477

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

inc/fields/timefield.class.php

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,52 @@ public function isPrerequisites() {
3535
return true;
3636
}
3737

38+
public function getDesignSpecializationField() {
39+
$rand = mt_rand();
40+
41+
$label = '';
42+
$field = '';
43+
44+
$additions = '<tr class="plugin_formcreator_question_specific">';
45+
$additions .= '<td>';
46+
$additions .= '<label for="dropdown_default_values'.$rand.'">';
47+
$additions .= __('Default values');
48+
$additions .= '</label>';
49+
$additions .= '</td>';
50+
$additions .= '<td>';
51+
$value = Html::entities_deep($this->question->fields['default_values']);
52+
if (version_compare(GLPI_VERSION, '9.5') >= 0 && method_exists(Html::class, 'showTimeField')) {
53+
$additions .= Html::showTimeField('default_values', [
54+
'type' => 'text',
55+
'id' => 'default_values',
56+
'value' => $value,
57+
'display' => false,
58+
]);
59+
} else {
60+
$additions .= static::showTimeField('default_values', [
61+
'type' => 'text',
62+
'id' => 'default_values',
63+
'value' => $value,
64+
'display' => false,
65+
]);
66+
}
67+
$additions .= '</td>';
68+
$additions .= '<td></td>';
69+
$additions .= '<td></td>';
70+
$additions .= '</tr>';
71+
72+
$common = parent::getDesignSpecializationField();
73+
$additions .= $common['additions'];
74+
75+
return [
76+
'label' => $label,
77+
'field' => $field,
78+
'additions' => $additions,
79+
'may_be_empty' => false,
80+
'may_be_required' => true,
81+
];
82+
}
83+
3884
public function displayField($canEdit = true) {
3985
if ($canEdit) {
4086
$id = $this->question->getID();
@@ -154,7 +200,7 @@ public function isAnonymousFormCompatible() {
154200
}
155201

156202
/**
157-
* Display TimeField form
203+
* Display TimeField form
158204
* @see Html::dateTime()
159205
*
160206
* @param string $name
@@ -194,7 +240,7 @@ protected static function showTimeField($name, $options = []) {
194240
$p['timestep'] = $CFG_GLPI['time_step'];
195241
}
196242

197-
// Those vars are set but not used ...
243+
// Those vars are set but not used ...
198244
// check Hml::showDateTimeField()
199245

200246
// $minHour = 0;

0 commit comments

Comments
 (0)