You are here

function _gathercontent_add_terms in GatherContent 7.2

Checks if a taxonomy term exists and adds it if needed.

1 call to _gathercontent_add_terms()
gathercontent_import_page in includes/pages_import.inc
AJAX function to process individual pages.

File

includes/pages_import.inc, line 180
Contains page field mapping form.

Code

function _gathercontent_add_terms($vocab, $terms) {
  if (is_array($terms)) {
    $terms = array_filter($terms);
  }
  else {
    $terms = array_filter(explode(',', strip_tags($terms)));
  }
  $tags = array();
  foreach ($terms as $term) {
    $term = trim($term);
    if (!empty($term)) {
      if ($tax = taxonomy_get_term_by_name($term, $vocab)) {
        $tid = $tax[key($tax)]->tid;
        $tags[] = entity_metadata_wrapper('taxonomy_term', $tid)
          ->value();
      }
      else {
        $tags[] = entity_property_values_create_entity('taxonomy_term', array(
          'name' => $term,
          'vocabulary' => $vocab,
        ))
          ->save()
          ->value();
      }
    }
  }
  return $tags;
}