function taxonomy_manager_move in Taxonomy Manager 7
Same name and namespace in other branches
- 5 taxonomy_manager.module \taxonomy_manager_move()
- 6.2 taxonomy_manager.admin.inc \taxonomy_manager_move()
- 6 taxonomy_manager.admin.inc \taxonomy_manager_move()
Moves terms in hierarchies to other parents
Parameters
$parents: Array of parent term ids to where children can be moved. Array should only contain more parents if multi hierarchy is enabled. If array contains 0, terms get moved to root level
$children: Array of term ids to move
$options: Array of additional options for moving 'keep_old_parents': if true, existing parents does not get deleted (only possible with multi hierarchies).
3 calls to taxonomy_manager_move()
- taxonomy_manager_double_tree_move_submit in ./
taxonomy_manager.admin.inc - taxonomy_manager_form_move_submit in ./
taxonomy_manager.admin.inc - Submit handler for moving terms
- taxonomy_manager_switch in ./
taxonomy_manager.admin.inc - Changes vocabulary of given terms and its children conflicts might be possible with multi-parent terms!
File
- ./
taxonomy_manager.admin.inc, line 2509
Code
function taxonomy_manager_move($parents, $children, $options = array()) {
if (!is_array($parents)) {
$parents = array(
$parents,
);
}
// Key parent terms array by tid, so that it is always unique.
$keyed_array = array();
foreach ($parents as $parent) {
$keyed_array[$parent] = $parent;
}
$parents = $keyed_array;
foreach ($children as $child) {
$term = taxonomy_term_load($child);
$term_parents = $parents;
if (isset($options['keep_old_parents']) && $options['keep_old_parents']) {
// Add existing parents to $term_parents array
$results = db_select('taxonomy_term_hierarchy', 'h')
->condition('tid', $child)
->fields('h')
->execute();
foreach ($results as $p) {
$term_parents[$p->parent] = $p->parent;
}
}
$term->parent = $term_parents;
taxonomy_term_save($term);
}
taxonomy_terms_static_reset();
}