You are here

function term_level_element_add_terms_submit in Term Level Field 7

Submit handler for additional terms.

Extracts existing and added terms and saves them under 'default_terms' and 'added_term' in $form_state.

1 string reference to 'term_level_element_add_terms_submit'
term_level_element_process in ./term_level_element.inc
Processes the term_level element type.

File

./term_level_element.inc, line 79
term_level_element form type

Code

function term_level_element_add_terms_submit($form, &$form_state) {
  $parents = $form_state['triggering_element']['#parents'];
  $field_values = $form_state['input'];
  for ($i = 0; $i < count($parents); $i++) {
    if ($parents[$i + 1] === 'tag_cloud_term_options') {
      break;
    }
    $field_values = $field_values[$parents[$i]];
  }
  $default_terms = array();
  $added_term = FALSE;
  foreach ($field_values as $group_id => $group) {

    // Table
    if (!empty($group['terms'])) {
      foreach ($group['terms'] as $tid => $level) {
        if ($tid != $group['tag_cloud_term_options']['select']) {
          $default_terms[$tid] = $level;
        }
      }
    }

    // Select List
    if ($group['tag_cloud_term_options']['select']) {
      $added_term = $group['tag_cloud_term_options']['select'];
    }
  }
  form_set_value($form, array(
    'default_terms' => $default_terms,
    'added_term' => $added_term,
  ), $form_state);
  $form_state['rebuild'] = TRUE;
}