function taxonomy_csv_thesaurus_create in Taxonomy CSV import/export 7.4
Prepare a regular thesaurus (Drupal 6 vocabulary) from a basic D7 vocabulary.
A regular and simplified thesaurus contains not only generic and specific terms (hierarchy of 'broader' and 'narrower' terms) and description, but links between them ('related' terms) and synonyms (non descriptor terms: 'used for' and 'use instead') too. This function creates such a vocabulary for Drupal 7.
Parameters
$name: Name of vocabulary. If vocabulary exists, it's updated, else it's created.
$synonym_field: (Optional) Array of field options. If FALSE, don't create synonym field. Warning: this module manages synonyms only if name is 'taxonomy_synonym'.
$relation_field: (Optional) Array of field options. If FALSE, don't create relation field. Warning: this module manages relations only if name is 'taxonomy_relation'.
Return value
Updated vocabulary object or FALSE
1 call to taxonomy_csv_thesaurus_create()
- _taxonomy_csv_import_vocabulary_prepare in import/
taxonomy_csv.import.api.inc - Prepare a vocabulary for import.
File
- ./
taxonomy_csv.vocabulary.api.inc, line 29 - Prepare and manage vocabularies.
Code
function taxonomy_csv_thesaurus_create($name = '', $synonym_field = array(), $relation_field = array()) {
// Load or create vocabulary.
$vocabulary = taxonomy_csv_vocabulary_name_check($name) ? taxonomy_csv_vocabulary_load_name($name) : taxonomy_csv_vocabulary_create($name);
// Prepare synonyms field if needed.
if ($synonym_field !== FALSE) {
$synonym_field += array(
'field_name' => 'taxonomy_synonym',
'label' => 'Synonyms',
'description' => 'Synonyms of this term',
'type' => 'text',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'translatable' => FALSE,
);
$result = taxonomy_csv_vocabulary_field_add($vocabulary->machine_name, $synonym_field);
}
// Prepare relations field if needed.
if ($relation_field !== FALSE) {
$relation_field += array(
'field_name' => 'taxonomy_relation',
'label' => 'Related terms',
'description' => 'Relations to other terms',
'type' => 'taxonomy_term_reference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'translatable' => FALSE,
'settings' => array(
'allowed_values' => array(
0 => array(
// Warning: Term reference field type need a specific vocabulary. This
// can create problems when this field is attached to another
// vocabulary. So vocabulary_field_add updates this type of field. Even
// if other vocabularies with this attached field have more references,
// previous references are always available. Another possibility may be
// the use of a specific taxonomy_relation field for each vocabulary,
// but it may be complicate to manage.
'vid' => $vocabulary->vid,
'parent' => 0,
),
),
),
);
$result = taxonomy_csv_vocabulary_field_add($vocabulary->machine_name, $relation_field);
}
return $vocabulary;
}