public function views_handler_filter_term_node_tid::validate_term_strings in Views (for Drupal 7) 7.3
Same name and namespace in other branches
- 6.3 modules/taxonomy/views_handler_filter_term_node_tid.inc \views_handler_filter_term_node_tid::validate_term_strings()
- 6.2 modules/taxonomy/views_handler_filter_term_node_tid.inc \views_handler_filter_term_node_tid::validate_term_strings()
Validate the user string. Since this can come from either the form or the exposed filter, this is abstracted out a bit so it can handle the multiple input sources.
Parameters
array $form: The form which is used, either the views ui or the exposed filters.
array $values: The taxonomy names which will be converted to tids.
Return value
array The taxonomy ids fo all validated terms.
2 calls to views_handler_filter_term_node_tid::validate_term_strings()
- views_handler_filter_term_node_tid::exposed_validate in modules/
taxonomy/ views_handler_filter_term_node_tid.inc - Validate the exposed handler form.
- views_handler_filter_term_node_tid::value_validate in modules/
taxonomy/ views_handler_filter_term_node_tid.inc - Validate the options form.
File
- modules/
taxonomy/ views_handler_filter_term_node_tid.inc, line 361 - Definition of views_handler_filter_term_node_tid.
Class
- views_handler_filter_term_node_tid
- Filter by term id.
Code
public function validate_term_strings(&$form, $values) {
if (empty($values)) {
return array();
}
$tids = array();
$names = array();
$missing = array();
foreach ($values as $value) {
$missing[strtolower($value)] = TRUE;
$names[] = $value;
}
if (!$names) {
return FALSE;
}
$query = db_select('taxonomy_term_data', 'td');
$query
->innerJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
$query
->fields('td');
$query
->condition('td.name', $names);
$query
->condition('tv.machine_name', $this->options['vocabulary']);
$query
->addTag('taxonomy_term_access');
$result = $query
->execute();
foreach ($result as $term) {
unset($missing[strtolower($term->name)]);
$tids[] = $term->tid;
}
if ($missing && !empty($this->options['error_message'])) {
form_error($form, format_plural(count($missing), 'Unable to find term: @terms', 'Unable to find terms: @terms', array(
'@terms' => implode(', ', array_keys($missing)),
)));
}
elseif ($missing && empty($this->options['error_message'])) {
$tids = array(
0,
);
}
return $tids;
}