function hs_taxonomy_hierarchical_select_create_item in Hierarchical Select 7.3
Same name and namespace in other branches
- 5.3 modules/hs_taxonomy.module \hs_taxonomy_hierarchical_select_create_item()
- 6.3 modules/hs_taxonomy.module \hs_taxonomy_hierarchical_select_create_item()
Implements hook_hierarchical_select_create_item().
TRICKY: No depth check is necessary in this function because HS's internal validation prevents an invalid parent.
File
- modules/
hs_taxonomy.module, line 800 - Implementation of the Hierarchical Select API for the Taxonomy module.
Code
function hs_taxonomy_hierarchical_select_create_item($label, $parent, $params) {
$term = new StdClass();
$term->vid = $params['vid'];
$term->name = html_entity_decode($label, ENT_QUOTES);
$term->description = '';
$term->parent = $parent;
$status = taxonomy_term_save($term);
if ($status !== FALSE) {
// Reset the cached tree.
_hs_taxonomy_hierarchical_select_get_tree($params['vid'], 0, -1, 1, TRUE);
// Retrieve the tid.
$children = _hs_taxonomy_hierarchical_select_get_tree($params['vid'], $parent, 1);
foreach ($children as $term) {
if ($term->name == $label) {
return $term->tid;
}
}
}
else {
return FALSE;
}
}