You are here

function taxonomy_manager_autocomplete_tags_get_tids in Taxonomy Manager 6

Same name and namespace in other branches
  1. 5 taxonomy_manager.module \taxonomy_manager_autocomplete_tags_get_tids()
  2. 6.2 taxonomy_manager.admin.inc \taxonomy_manager_autocomplete_tags_get_tids()
  3. 7 taxonomy_manager.admin.inc \taxonomy_manager_autocomplete_tags_get_tids()

helper function for getting out of term ids from autocomplete fields non-exsiting terms get inserted autmatically (part of taxonomy_node_save)

Parameters

$typed_input input string of form field:

$vid vocabulary id:

Return value

array of term ids

4 calls to taxonomy_manager_autocomplete_tags_get_tids()
taxonomy_manager_form_merge_submit in ./taxonomy_manager.admin.inc
Submit handler for merging terms
taxonomy_manager_form_move_submit in ./taxonomy_manager.admin.inc
Submit handler for moving terms
taxonomy_manager_form_submit in ./taxonomy_manager.admin.inc
submits the taxonomy manager form (only search button)
taxonomy_manager_term_data_edit in ./taxonomy_manager.admin.inc
callback handler for updating term data

File

./taxonomy_manager.admin.inc, line 1315

Code

function taxonomy_manager_autocomplete_tags_get_tids($typed_input, $vid, $insert_new = TRUE) {
  $tids = array();
  $regexp = '%(?:^|,\\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x';
  preg_match_all($regexp, $typed_input, $matches);
  $typed_terms = array_unique($matches[1]);
  foreach ($typed_terms as $typed_term) {
    $typed_term = str_replace('""', '"', preg_replace('/^"(.*)"$/', '\\1', $typed_term));
    $typed_term = trim($typed_term);
    if ($typed_term == "") {
      continue;
    }
    $possibilities = taxonomy_get_term_by_name($typed_term);
    $typed_term_tid = NULL;

    // tid match if any.
    foreach ($possibilities as $possibility) {
      if ($possibility->vid == $vid) {
        $typed_term_tid = $possibility->tid;
        $tids[$typed_term_tid]['tid'] = $typed_term_tid;
      }
    }
    if (!$typed_term_tid && $insert_new) {
      $edit = array(
        'vid' => $vid,
        'name' => $typed_term,
      );
      $status = taxonomy_save_term($edit);
      $typed_term_tid = $edit['tid'];
      $tids[$typed_term_tid]['tid'] = $typed_term_tid;
      $tids[$typed_term_tid]['new'] = TRUE;
    }
  }
  return $tids;
}