You are here

function image_attach_image_add_submit in Image 6

Save attached image nids and rebuild form.

This submit function adds the new images and returns to the node edit form directly afterwards, without creating the new node yet.

1 string reference to 'image_attach_image_add_submit'
image_attach_form_alter in contrib/image_attach/image_attach.module
Implementation of hook_form_alter().

File

contrib/image_attach/image_attach.module, line 356
image_attach.module

Code

function image_attach_image_add_submit(&$form, &$form_state) {

  // Rebuild the attached image data.
  if (isset($form_state['values']['iids'])) {
    db_query("DELETE FROM {image_attach} WHERE nid = %d", $form['nid']['#value']);

    // Sort the $form_state['values']['iids'] array by weight.
    if (count($form_state['values']['image_thumbnail'])) {
      $form_state['values']['iids'] = _image_attach_set_image_weight($form_state['values']['image_thumbnail'], $form_state['values']['iids']);
    }
    if (count($form_state['values']['iids'])) {
      $weight = 0;
      foreach ($form_state['values']['iids'] as $iid) {
        db_query("INSERT INTO {image_attach} (nid, iid, weight) VALUES (%d, %d, %d)", $form['nid']['#value'], $iid, $weight++);
      }
    }
  }

  // Convert taxonomy format from Preview to Object.
  if (module_exists('taxonomy') && !empty($form_state['values']['taxonomy'])) {
    $temp_node = new stdClass();
    $temp_node->taxonomy = $form_state['values']['taxonomy'];
    $form_state['values']['taxonomy'] = taxonomy_preview_terms($temp_node);
    unset($temp_node);
  }

  // Rebuild the node edit form.
  node_form_submit_build_node($form, $form_state);
}