public function SearchApiViewsHandlerFilterFulltext::exposed_validate in Search API 7
Validate the exposed handler form.
Overrides views_handler::exposed_validate
File
- contrib/
search_api_views/ includes/ handler_filter_fulltext.inc, line 97 - Contains SearchApiViewsHandlerFilterFulltext.
Class
- SearchApiViewsHandlerFilterFulltext
- Views filter handler class for handling fulltext fields.
Code
public function exposed_validate(&$form, &$form_state) {
// Only validate exposed input.
if (empty($this->options['exposed']) || empty($this->options['expose']['identifier'])) {
return;
}
// Don't validate on form reset.
if (!empty($form_state['triggering_element']['#value']) && !empty($form['reset']['#value']) && $form_state['triggering_element']['#value'] === $form['reset']['#value']) {
return;
}
// We only need to validate if there is a minimum word length set.
if ($this->options['min_length'] < 2) {
return;
}
$identifier = $this->options['expose']['identifier'];
$input =& $form_state['values'][$identifier];
if ($this->options['is_grouped'] && isset($this->options['group_info']['group_items'][$input])) {
$this->operator = $this->options['group_info']['group_items'][$input]['operator'];
$input =& $this->options['group_info']['group_items'][$input]['value'];
}
// If there is no input, we're fine.
if (!trim($input)) {
return;
}
$words = preg_split('/\\s+/', $input);
$quoted = FALSE;
foreach ($words as $i => $word) {
$word_length = drupal_strlen($word);
if (!$word_length) {
unset($words[$i]);
continue;
}
// Protect quoted strings.
if ($quoted && $word[strlen($word) - 1] === '"') {
$quoted = FALSE;
continue;
}
if ($quoted || $word[0] === '"') {
$quoted = TRUE;
continue;
}
if ($word_length < $this->options['min_length']) {
unset($words[$i]);
}
}
if (!$words) {
$vars['@count'] = $this->options['min_length'];
$msg = t('You must include at least one positive keyword with @count characters or more.', $vars);
form_error($form[$identifier], $msg);
}
$input = implode(' ', $words);
}