You are here

function views_handler_filter_term_node_tid::validate_term_strings in Views (for Drupal 7) 6.3

Same name and namespace in other branches
  1. 6.2 modules/taxonomy/views_handler_filter_term_node_tid.inc \views_handler_filter_term_node_tid::validate_term_strings()
  2. 7.3 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.

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 255

Class

views_handler_filter_term_node_tid
Filter by term id.

Code

function validate_term_strings(&$form, $values) {
  if (empty($values)) {
    return array();
  }
  $tids = array();
  $placeholders = array();
  $args = array();
  $results = array();
  foreach ($values as $value) {
    $missing[strtolower($value)] = TRUE;
    $args[] = $value;
    $placeholders[] = "'%s'";
  }
  if (!$args) {
    return;
  }

  // add the taxonomy vid to the argument list.
  $args[] = $this->options['vid'];
  $result = db_query("SELECT * FROM {term_data} td WHERE td.name IN (" . implode(', ', $placeholders) . ") AND td.vid = %d", $args);
  while ($term = db_fetch_object($result)) {
    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;
}