You are here

function hs_taxonomy_hierarchical_select_create_item in Hierarchical Select 6.3

Same name and namespace in other branches
  1. 5.3 modules/hs_taxonomy.module \hs_taxonomy_hierarchical_select_create_item()
  2. 7.3 modules/hs_taxonomy.module \hs_taxonomy_hierarchical_select_create_item()

Implementation of hook_hierarchical_select_create_item().

1 call to hs_taxonomy_hierarchical_select_create_item()
hs_content_taxonomy_hierarchical_select_create_item in modules/hs_content_taxonomy.module
Implementation of hook_hierarchical_select_create_item().

File

modules/hs_taxonomy.module, line 521
Implementation of the Hierarchical Select API for the Taxonomy module.

Code

function hs_taxonomy_hierarchical_select_create_item($label, $parent, $params) {
  $form_state['values'] = array(
    'name' => html_entity_decode($label, ENT_QUOTES),
    'parent' => $parent,
    'vid' => $params['vid'],
  );
  $status = taxonomy_save_term($form_state['values']);
  if ($status == SAVED_NEW) {

    // Reset the cached tree.
    _hs_taxonomy_hierarchical_select_get_tree($params['vid'], 0, -1, 1, TRUE);

    // Retrieve the tid.
    $children = taxonomy_get_children($parent, $params['vid']);
    foreach ($children as $tid => $term) {
      if ($term->name == $label) {
        return $tid;
      }
    }
  }
  else {
    return FALSE;
  }
}