You are here

function data_taxonomy_ajax_save in Data 6

AHAH callback for saving terms.

@todo: Verify form token.

1 string reference to 'data_taxonomy_ajax_save'
data_taxonomy_menu in data_taxonomy/data_taxonomy.module
Implementation of hook_menu().

File

data_taxonomy/data_taxonomy.module, line 411
Hooks and API functions for Data Node module.

Code

function data_taxonomy_ajax_save() {
  $cached_form_state = array();
  $files = array();
  $cached_form = form_get_cache($_POST['form_build_id'], $cached_form_state);
  if ($cached_form['form_token']['#default_value'] == $_POST['form_token']) {

    // Rebuild $form_state['values'].
    $form_state = array(
      'values' => $_POST,
    );
    foreach (element_children($cached_form) as $elem) {
      if ($cached_form[$elem]['#type'] === 'value' && isset($cached_form[$elem]['#value'])) {
        $form_state['values'][$elem] = $cached_form[$elem]['#value'];
      }
    }

    // Process and save terms & relations.
    $values = $form_state['values'];
    $terms = data_taxonomy_save_tags($values['tags'], $values['vid']);
    _data_taxonomy_save_relations($values['vid'], $values['id'], $values['table_name'], array_keys($terms));
    drupal_json(array(
      'status' => 1,
      'data' => theme('links', data_taxonomy_tag_links($terms, $_POST['path'], explode('&', $_POST['args'])), array(
        'class' => 'links data-taxonomy-tags',
      )),
    ));
    exit;
  }
  drupal_json(array(
    'status' => 1,
    'data' => 'Error submitting form',
  ));
  exit;
}