You are here

function hs_taxonomy_hierarchical_select_create_item in Hierarchical Select 5.3

Same name and namespace in other branches
  1. 6.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 314
Implementation of the Hierarchical Select API for the Taxonomy module.

Code

function hs_taxonomy_hierarchical_select_create_item($label, $parent, $params) {
  $form_values = array(
    'name' => html_entity_decode($label, ENT_QUOTES),
    'parent' => $parent,
    'vid' => $params['vid'],
  );
  $status = taxonomy_save_term($form_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;
  }
}