1 views_handler_filter_term_node_tid.inc views_handler_filter_term_node_tid::validate_term_strings(&$form, $values)

Validate the user string. In order to handle multiple input sources, this is abstracted out a bit; since this can come from either the form, or the exposed filter.

Parameters

$form: The form which is used, either the views ui or the exposed filters.

$values: The taxonomy names which will be converted to tids.

Return value

array: The taxonomy ids fo all validated terms.

File

core/modules/taxonomy/views/views_handler_filter_term_node_tid.inc, line 306
Definition of views_handler_filter_term_node_tid.

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();
  $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->fields('td');
  $query->condition('td.name', $names);
  $query->condition('td.vocabulary', $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;
}