You are here

function taxonomy_csv_term_save in Taxonomy CSV import/export 6.4

Same name and namespace in other branches
  1. 6.5 taxonomy_csv.term.api.inc \taxonomy_csv_term_save()
  2. 6.2 taxonomy_csv.term.api.inc \taxonomy_csv_term_save()
  3. 6.3 taxonomy_csv.term.api.inc \taxonomy_csv_term_save()

Save by reference an internally formatted term object.

Drupal taxonomy_save_term uses a text area format to save synonyms. This helper convert a synonym array into a string before using it. It converts 'parents', such in Drupal 7, to 'parent' too.

Parameters

$term: A term object to save by reference. Term is an object containing:

  • 'name' : term name string,
  • 'vid' : the vocabulary id,

and eventually:

  • 'tid' : term id in case of an update,
  • 'description' : description string,
  • 'weight' : weight integer,
  • 'parents' : array of first level parent tids,
  • 'relations' : array of related tids,
  • 'synonyms' : array of synonyms terms names strings,

Return value

Status value (SAVED_NEW or SAVED_UPDATED). Term is updated with its tid.

2 calls to taxonomy_csv_term_save()
taxonomy_csv_term_import in import/taxonomy_csv.import.line.api.inc
Update or create a term with the given name in the given vocabulary and given parent.
taxonomy_csv_vocabulary_duplicate in ./taxonomy_csv.vocabulary.api.inc
Duplicates a vocabulary object. If not exist, creates an empty vocabulary.

File

./taxonomy_csv.term.api.inc, line 268
Find, get and set full or detail term items.

Code

function taxonomy_csv_term_save(&$term) {
  $term_to_save = (array) $term;
  if (isset($term->synonyms)) {
    $term_to_save['synonyms'] = implode("\n", $term->synonyms);
  }
  if (isset($term->parents)) {
    $term_to_save['parent'] = $term->parents;
    unset($term_to_save['parents']);
  }
  else {
    $term_to_save['parent'] = array(
      0,
    );
    $term->parents = array(
      0,
    );
  }

  // Term is automaticaly updated, because it's used by reference.
  // Return either SAVED_NEW or SAVED_UPDATED.
  $result = taxonomy_save_term($term_to_save);

  // Update term.
  $term->tid = $term_to_save['tid'];
  return $result;
}