Skip to content

Commit

Permalink
fix(form_validator): import valodators from JSON
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Mar 13, 2019
1 parent d3aeb0d commit b6ea017
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,13 @@ public static function import(PluginFormcreatorImportLinker $importLinker, $form
}
}

if ($forms_id
&& isset($form['_validators'])) {
foreach ($form['_validators'] as $validator) {
PluginFormcreatorForm_Validator::import($forms_id, $validator);
}
}

return $forms_id;
}

Expand Down
15 changes: 15 additions & 0 deletions inc/form_validator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ public static function import($forms_id = 0, $validator = []) {

$validator['plugin_formcreator_forms_id'] = $forms_id;

// Find the validator
if (!in_array($validator['itemtype'], [User::class, Group::class])) {
return false;
}
$linkedItemtype = $validator['itemtype'];
$linkedItem = new $linkedItemtype();
$crit = [
'name' => $validator['_item'],
];
if (!$linkedItem->getFromDBByName($crit)) {
// validator not found. Let's ignore it
return false;
}
$validator['items_id'] = $linkedItem->getID();

if ($validators_id = plugin_formcreator_getFromDBByField($item, 'uuid', $validator['uuid'])) {
// add id key
$validator['id'] = $validators_id;
Expand Down

0 comments on commit b6ea017

Please sign in to comment.