You are here

function content_taxonomy_tree_process in Content Taxonomy 6

Same name and namespace in other branches
  1. 6.2 content_taxonomy_tree.module \content_taxonomy_tree_process()

Processes the content_taxonomy_tree form element

uses the 'taxonomy_manager_tree' element type

1 string reference to 'content_taxonomy_tree_process'
content_taxonomy_tree_elements in ./content_taxonomy_tree.module
Implementation of hook_elements().

File

./content_taxonomy_tree.module, line 91

Code

function content_taxonomy_tree_process($element, $edit, &$form_state, $form) {
  $field_name = $element['#field_name'];
  $field = $form['#field_info'][$field_name];
  $field_key = $element['#columns'][0];
  if (is_array($element['#value'])) {
    if (array_key_exists($field_key, $element['#value'])) {

      //validation function where values are set haven't been called yet for this form element

      //because some other element might have caused an validation error

      //so we have to do the processing of the values here
      if ($field['multiple']) {
        $selected_terms = _taxonomy_manager_tree_get_selected_terms($element['#value']['value']);
        $element['#value'] = content_transpose_array_rows_cols(array(
          $field_key => array_values($selected_terms),
        ));
      }
    }
    $element['#value'] = content_taxonomy_tree_data2form($element, $element['#value'], $field);
  }
  $element[$field_key] = array(
    '#type' => 'taxonomy_manager_tree',
    '#default_value' => isset($element['#value']) ? $element['#value'] : '',
    '#vid' => $field['vid'],
    '#parent' => content_taxonomy_field_get_parent($field),
    '#default_value' => is_array($element['#value']) ? $element['#value'] : array(),
    '#render_whole_tree' => TRUE,
    '#pager' => FALSE,
    '#add_term_info' => FALSE,
    '#expand_all' => $field['widget']['expand_all'],
    '#tree_is_required' => $field['required'],
    //using tree_is_required instead of required, prevents that error messages are shown twice
    '#required' => FALSE,
    '#multiple' => isset($field['multiple']) ? $field['multiple'] : FALSE,
    '#field_name' => $element['#field_name'],
    '#delta' => $element['#delta'],
    '#columns' => $element['#columns'],
    '#title' => $element['#title'],
    '#description' => $element['#description'],
  );

  // Make sure field info will be available to the validator which
  // does not get the values in $form.
  $form_state['#field_info'][$field['field_name']] = $field;
  return $element;
}