You are here

function csvancestry_set_parent in Taxonomy import/export via XML 7

Same name and namespace in other branches
  1. 6.2 csvancestry_format.inc \csvancestry_set_parent()

Set the parent of this term. $term must be a valid term. parent term may be invented on the fly.

1 call to csvancestry_set_parent()
cvsancestry_import_row in formats/csvancestry_format.inc

File

formats/csvancestry_format.inc, line 143

Code

function csvancestry_set_parent($term, $parent_name) {
  if ($parent_name == $term->name) {
    drupal_set_message(t("Not setting %name as a child of itself", array(
      '%name' => $term->name,
    )));
    continue;
  }
  $parent_term = _taxonomy_xml_get_term_placeholder($parent_name, $term->vid);
  if (empty($parent_term->tid)) {
    $parent_data = (array) $parent_term;
    taxonomy_term_save($term);

    // Retrieve the term object to get hold of the tid if needed
    $parent_term = taxonomy_xml_get_term_by_name_from_vocab($parent_name, $term->vid);
  }
  if ($parent_term && isset($parent_term->tid)) {
    drupal_set_message(t("!name # %tid is a child of !parent # %ptid ", array(
      '!name' => $term->name,
      '%tid' => $term->tid,
      '!parent' => l($parent_term->name, 'taxonomy/term/' . $parent_term->tid),
      '%ptid' => $parent_term->tid,
    )));
    $term->parents[$parent_term->tid] = $parent_term->tid;
  }
}