Skip to content

Commit e431d5d

Browse files
committed
fix(form): validator setting broken
1 parent f13b52b commit e431d5d

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

inc/form.class.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,15 @@ public function showForm($ID, $options = []) {
457457
$usersCondition = [
458458
"$userTable.id" => new QuerySubquery($subQuery)
459459
];
460-
460+
$formValidator = new PluginFormcreatorForm_Validator();
461+
$validatorUsers = $formValidator->getValidatorsForForm($this, User::class);
462+
$validatorUser = array_shift($validatorUsers);
461463
echo '<div id="validators_users">';
462464
Dropdown::show(
463465
User::class, [
464-
'condition' => $usersCondition
466+
'name' => '_validator_users',
467+
'value' => $validatorUser ? $validatorUser->fields['items_id'] : 0,
468+
'condition' => $usersCondition,
465469
]
466470
);
467471
echo '</div>';
@@ -511,10 +515,15 @@ public function showForm($ID, $options = []) {
511515
$groupsCondition = [
512516
"$groupTable.id" => new QuerySubquery($subQuery),
513517
];
518+
$formValidator = new PluginFormcreatorForm_Validator();
519+
$validatorgroups = $formValidator->getValidatorsForForm($this, Group::class);
520+
$validatorgroup = array_shift($validatorgroups);
514521
echo '<div id="validators_groups" style="width: 100%">';
515522
Dropdown::show(
516523
Group::class, [
517-
'condition' => $groupsCondition
524+
'name' => '_validator_groups',
525+
'value' => $validatorgroup ? $validatorgroup->fields['items_id'] : 0,
526+
'condition' => $groupsCondition
518527
]
519528
);
520529

@@ -1220,9 +1229,9 @@ class='formcreator_form form_horizontal'>";
12201229
$validators = [0 => Dropdown::EMPTY_VALUE];
12211230

12221231
// Groups
1232+
$formFk = self::getForeignKeyField();
12231233
if ($this->fields['validation_required'] == 2) {
12241234
$groupTable = Group::getTable();
1225-
$formFk = self::getForeignKeyField();
12261235
$result = $DB->request([
12271236
'SELECT' => [
12281237
$groupTable => ['id', 'completename']
@@ -1420,6 +1429,9 @@ private function updateValidators() {
14201429
$validatorItemtype = Group::class;
14211430
break;
14221431
}
1432+
if (!is_array($validators)) {
1433+
$validators = [$validators];
1434+
}
14231435
foreach ($validators as $itemId) {
14241436
$form_validator = new PluginFormcreatorForm_Validator();
14251437
$form_validator->add([

inc/form_validator.class.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
* ---------------------------------------------------------------------
3030
*/
3131

32+
use tests\units\PluginFormcreatorForm_Validator as TestsPluginFormcreatorForm_Validator;
33+
3234
if (!defined('GLPI_ROOT')) {
3335
die("Sorry. You can't access this file directly");
3436
}
@@ -40,7 +42,7 @@ class PluginFormcreatorForm_Validator extends CommonDBRelation implements
4042
PluginFormcreatorExportableInterface
4143
{
4244

43-
// From CommonDBRelation
45+
// From CommonDBRelation
4446
static public $itemtype_1 = PluginFormcreatorForm::class;
4547
static public $items_id_1 = 'plugin_formcreator_forms_id';
4648

@@ -151,4 +153,31 @@ public function export($remove_uuid = false) {
151153

152154
return $validator;
153155
}
156+
157+
/**
158+
* Get validators of type $itemtype associated to a form
159+
*
160+
* @param PluginFormcreatorForm $form
161+
* @param string $itemtype
162+
* @return void
163+
*/
164+
public function getValidatorsForForm(PluginFormcreatorForm $form, $itemtype) {
165+
if (!in_array($itemtype, [User::class, Group::class])) {
166+
return [];
167+
}
168+
169+
$result = [];
170+
$found = $this->find([
171+
PluginFormcreatorForm::getForeignKeyField() => $form->getID(),
172+
'itemtype' => $itemtype,
173+
]);
174+
foreach($found as $id => $row) {
175+
$item = new self();
176+
if ($item->getFromDB($id)) {
177+
$result[$id] = $item;
178+
}
179+
}
180+
181+
return $result;
182+
}
154183
}

inc/formlist.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ static function getMenuContent() {
5050
global $CFG_GLPI;
5151

5252
$menu = parent::getMenuContent();
53+
$menu['title'] = __('Forms waiting for validation', 'formcreator');
54+
$menu['page'] = '/plugins/formcreator/front/formlist.php';
5355
$image = '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/check.png"
5456
title="' . __('Forms waiting for validation', 'formcreator') . '"
5557
alt="' . __('Forms waiting for validation', 'formcreator') . '">';

0 commit comments

Comments
 (0)