function _ad_ui_install_taxonomy_terms in Advertisement 7.3
Creates the specified taxonomy terms.
Parameters
object $vocabulary: The vocabulary object terms should belong to.
array $terms: An array of term definitions: a term name or a full term array data structure.
1 call to _ad_ui_install_taxonomy_terms()
- _ad_ui_install_taxonomy in modules/
ad_ui/ ad_ui.drush.inc - Install taxonomy data.
File
- modules/
ad_ui/ ad_ui.drush.inc, line 75
Code
function _ad_ui_install_taxonomy_terms($vocabulary, $terms) {
$weight = 0;
$tids = array();
$instances = field_info_instances('taxonomy_term', $vocabulary->machine_name);
foreach ($terms as $definition) {
// Init term definition.
if (is_string($definition)) {
$definition = array(
'name' => $definition,
);
}
$definition['vid'] = $vocabulary->vid;
$definition['weight'] = $weight++;
// Resolve the parent ID if set.
if (isset($definition['parent'])) {
$definition['parent'] = $tids[$definition['parent']];
}
// Expand field values.
foreach ($definition as $key => $value) {
if (isset($instances[$key]) && !is_array($value)) {
$definition[$key] = array(
LANGUAGE_NONE => array(
array(
'value' => $definition[$key],
),
),
);
}
}
// Create term.
$term = (object) $definition;
taxonomy_term_save($term);
$tids[] = $term->tid;
}
}