You are here

function views_handler_filter_tid_custom in Views (for Drupal 7) 5

1 string reference to 'views_handler_filter_tid_custom'
taxonomy_views_tables in modules/views_taxonomy.inc
This include file implements views functionality on behalf of taxonomy.module

File

modules/views_taxonomy.inc, line 435

Code

function views_handler_filter_tid_custom($op, $filter, $filterinfo, &$query) {

  //if there is an autocomplete field, we have to transform the string values into the tids
  if ($filterinfo['tags']) {

    // This regexp allows the following types of user input:
    // this, "somecmpany, llc", "and ""this"" w,o.rks", foo bar
    $regexp = '%(?:^|,\\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x';
    preg_match_all($regexp, $filter['value'][0], $matches);
    $typed_terms = array_unique($matches[1]);
    $filter['value'] = array();
    foreach ($typed_terms as $typed_term) {

      // If a user has escaped a term (to demonstrate that it is a group,
      // or includes a comma or quote character), we remove the escape
      // formatting like taxonomye_node_save()
      $typed_term = str_replace('""', '"', preg_replace('/^"(.*)"$/', '\\1', $typed_term));
      $typed_term = trim($typed_term);
      if ($typed_term == "") {
        continue;
      }

      // See if the term exists in the chosen vocabulary
      // and return the tid, otherwise, add a new record.
      $possibilities = taxonomy_get_term_by_name($typed_term);
      foreach ($possibilities as $possibility) {
        if ($possibility->vid == $filterinfo['vocabulary']) {
          $filter['value'][] = $possibility->tid;
        }
      }
    }
  }
  _views_add_taxonomy($filter['operator'], $filter['value'], $filter['options'], $query);
}