function taxonomy_xml_taxonomy_term_load in Taxonomy import/export via XML 7
Same name and namespace in other branches
- 6.2 taxonomy_xml.module \taxonomy_xml_taxonomy_term_load()
Appends any missing data to the given term - by ref.
Native taxonomy_term_load does not normally pick up the parents too. I do here.
TODO now that hook_taxonomy_term_load is in core, need to check if this will affect performance.
Parameters
$terms: An array of term objects, indexed by tid.
File
- ./
taxonomy_xml.module, line 791 - Make it possible to import and export taxonomies as XML documents.
Code
function taxonomy_xml_taxonomy_term_load($terms) {
// Confusing. hook_taxonomy_term_load says it accepts an ARRAY of terms
// yet it's being called with a single term.
if (!is_array($terms)) {
watchdog('taxonomy_xml', 'taxonomy_xml_taxonomy_term_load called with a non-array. This means an API call somewhere is out of date.', array(), WATCHDOG_WARNING);
$terms = array(
$terms,
);
}
foreach ($terms as $tid => &$term) {
if (!is_object($term)) {
watchdog('taxonomy_xml', 'taxonomy_xml_taxonomy_term_load running on a non-object, term[!tid] = <pre>!term</pre>', array(
'!tid' => $tid,
'!term' => print_r($term, 1),
), WATCHDOG_WARNING);
}
// Earlier version of core did not init the parents array all the time..?
// Do it ourselves.
// Core seems confused about sometimes using 'parent' and sometimes 'parents'
// It seems that when core uses 'parents' it's a fully loaded object, used mosly in admin
// but core 'parent' is an array of ids, BUT it gets messed up with odd values sometimes.
// I will use 'parents' most of the time internally, but need to flatten
// to 'parent' just before saving with taxonomy_term_save().
if (empty($term->parents)) {
if ($parent_list = array_keys(taxonomy_get_parents($tid))) {
$term->parents = array_combine($parent_list, $parent_list);
}
}
#$term->synonyms_array = taxonomy_get_synonyms($term->tid);
####
// ->uri is now reserved for entities in d7?
if ($guid = taxonomy_xml_get_term_guid($term)) {
$term->guid = $guid;
}
}
}