You are here

function content_taxonomy_et_get_first_possible_term in Content Taxonomy 7

Helper function that retrieves the first possible term object for a given term name and and array of vocabulary ids.

Used in content_taxonomy_et_autocomplete_validate().

1 call to content_taxonomy_et_get_first_possible_term()
content_taxonomy_et_autocomplete_validate in ./content_taxonomy_et.module
Replacement for form validate handler taxonomy_autocomplete_validate().

File

./content_taxonomy_et.module, line 383
Entity Translation integration for taxonomy terms.

Code

function content_taxonomy_et_get_first_possible_term($term_name, $vids) {
  global $language;

  // EFQ does not work here, as we do not have OR condition possibilities.
  $query = db_select('taxonomy_term_data', 't');
  $query
    ->addTag('translatable');
  $query
    ->addTag('term_access');
  $query
    ->leftJoin('field_data_name_field', 'fd', 'fd.entity_id = t.tid AND fd.entity_type = :type AND fd.language = :language', array(
    ':type' => 'taxonomy_term',
    ':language' => $language->language,
  ));
  $query
    ->fields('t', array(
    'tid',
  ))
    ->condition('t.vid', $vids, 'IN')
    ->condition(db_or()
    ->condition('t.name', $term_name)
    ->condition('fd.name_field_value', $term_name))
    ->orderBy('t.tid', 'ASC')
    ->execute();
  $first_tid = $query
    ->execute()
    ->fetchColumn();
  if (!empty($first_tid)) {
    $term = taxonomy_term_load($first_tid);
    return $term;
  }
  return FALSE;
}