Commit ecb60882 authored by Tino Goratsch's avatar Tino Goratsch

- converted the Search module to use the new validation facility

parent 19533611
......@@ -18,6 +18,6 @@ class NotEmptyValidationRule extends AbstractValidationRule
return $this->isValid($data[$field], $field, $extra);
}
return !empty(trim($data));
return !empty(is_array($data) ? $data : trim($data));
}
}
\ No newline at end of file
......@@ -16,20 +16,42 @@ class Validator extends Core\Validator\AbstractValidator
*/
public function validate(array $formData)
{
$this->errors = [];
if (strlen($formData['search_term']) < 4) {
$this->errors['search-term'] = $this->lang->t('search', 'search_term_to_short');
}
if (empty($formData['mods'])) {
$this->errors['mods'] = $this->lang->t('search', 'no_module_selected');
}
if (empty($formData['area'])) {
$this->errors['area'] = $this->lang->t('search', 'no_area_selected');
}
if (empty($formData['sort']) || $formData['sort'] != 'asc' && $formData['sort'] != 'desc') {
$this->errors['sort'] = $this->lang->t('search', 'no_sorting_selected');
}
$this->validator
->addConstraint(
Core\Validator\ValidationRules\MinLengthValidationRule::NAME,
[
'data' => $formData,
'field' => 'search_term',
'message' => $this->lang->t('search', 'search_term_to_short'),
'extra' => [
'length' => 4
]
])
->addConstraint(
Core\Validator\ValidationRules\NotEmptyValidationRule::NAME,
[
'data' => $formData,
'field' => 'mods',
'message' => $this->lang->t('search', 'no_module_selected')
])
->addConstraint(
Core\Validator\ValidationRules\NotEmptyValidationRule::NAME,
[
'data' => $formData,
'field' => 'area',
'message' => $this->lang->t('search', 'no_area_selected')
])
->addConstraint(
Core\Validator\ValidationRules\InArrayValidationRule::NAME,
[
'data' => $formData,
'field' => 'sort',
'message' => $this->lang->t('search', 'no_sorting_selected'),
'extra' => [
'haystack' => ['asc', 'desc']
]
]);
$this->_checkForFailedValidation();
$this->validator->validate();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment