public function ManageSortFieldsForm::validateForm in Search API sorts 8
Form validation handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormBase::validateForm
File
- src/
Form/ ManageSortFieldsForm.php, line 311
Class
- ManageSortFieldsForm
- Provides a form for managing sort fields for a search api display.
Namespace
Drupal\search_api_sorts\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
foreach ($form_state
->getValue('sorts') as $key => $v) {
if ($v['status']) {
if (!$v['label']) {
$form_state
->setErrorByName("sorts][{$key}][label", $this
->t("You can't set an empty label."));
}
elseif (strlen($v['label']) > 80) {
$form_state
->setErrorByName("sorts][{$key}][label", $this
->t('Labels cannot be longer than 80 characters, but "@label" is @count characters long.', [
'@label' => $v['label'],
'@count' => strlen($v['label']),
]));
}
}
}
}