You are here

function location_taxonomize_term_attach in Location Taxonomize 7.2

Attaches the given tids to the node form given in form_state if they need to be attached Note that all it does is remove the old numbers and add the new ones. It's faster than checking which ones are missing and adding. Also ensures that only the terms that are relevant are getting saved.

1 call to location_taxonomize_term_attach()
location_taxonomize_taxonomize in ./location_taxonomize.module

File

./location_taxonomize.module, line 391

Code

function location_taxonomize_term_attach($tids, $form, &$form_state) {
  $lang = 'und';

  // check that the field exists and is set up correctly
  $field = location_taxonomize_term_attach_check_field($form);
  if ($field == FALSE) {
    drupal_set_message(t('Location Taxonomize could not attach the terms to the node because the Taxonomy Reference field is not set up correctly'), 'warning');
    return;
  }

  // empty the currently set values
  $form_state['values'][$field][$lang] = array();

  // Reverse the order to assign the lowest term in the hierarchy first
  $tids = array_reverse($tids);

  // add the values
  $tids = array_unique($tids);
  foreach ($tids as $tid) {
    $form_state['values'][$field][$lang][]['tid'] = $tid;
  }
}