Hi,

as the topic says, I want to add some terms to a vocabulary in my module code.

In the install hook in my module I create a vocabulary but I can't find out how to add some starting entries to it. I've grep'ed through the entire drupal codebase but there is no "INSERT INTO {term_data}" anywhere, which I find odd. How does the data wind up there, because it does indeed.

I've searched everywhere for some decent documentation/tutorial on how to use the taxonomy functions but I cannot find any. Does anyone have some tips?

Thanks!

Comments

nevets’s picture

The function is taxonomy_save_term() which is found in taxonomy.module.

spatch’s picture

I did notice it but it was documented as "Helper function for taxonomy_form_term_submit()" so I figured it was just some internal stuff not to be used by others.

When I checked out the code closer, this function uses
drupal_write_record('term_data', ...) which explains why I didn't find any 'INSERT INTO {term_data}'

In case anyone wants to know (and happens to read this), taxonomy_save_term() accepts an array with the following parameters:

$form_values = array(
  'vid' => $vocabulary_id,
  'name' => 'myterm', // if this param is empty but 'tid' is set the term is deleted
  'description' => 'description of the term',
  'tid' => 0, // null/0 if this is a new term
  'relations' => array($tid2, $tid3, ...),
  'parent' => $tid_of_parent_term_or_0,
  'synonyms' => "synonyms\nseparated by\nnewlines"
);
vgodard’s picture

@spatch : that was helpful ! Thanks !