function upload_node_form_submit

You are here

6 upload.module upload_node_form_submit(&$form, &$form_state)

Save new uploads and store them in the session to be associated to the node on upload_save.

Parameters

$node: A node object to associate with uploaded files.

1 call to upload_node_form_submit()
upload_js in modules/upload/upload.module
Menu-callback for JavaScript-based uploads.
1 string reference to 'upload_node_form_submit'
upload_form_alter in modules/upload/upload.module

File

modules/upload/upload.module, line 175
File-handling and attaching files to nodes.

Code

function upload_node_form_submit(&$form, &$form_state) {
  global $user;

  $limits = _upload_file_limits($user);
  $validators = array(
    'file_validate_extensions' => array($limits['extensions']),
    'file_validate_image_resolution' => array($limits['resolution']),
    'file_validate_size' => array($limits['file_size'], $limits['user_size']),
  );

  // Save new file uploads.
  if (user_access('upload files') && ($file = file_save_upload('upload', $validators, file_directory_path()))) {
    $file->list = variable_get('upload_list_default', 1);
    $file->description = $file->filename;
    $file->weight = 0;
    $file->new = TRUE;
    $form['#node']->files[$file->fid] = $file;
    $form_state['values']['files'][$file->fid] = (array) $file;
  }

  if (isset($form_state['values']['files'])) {
    foreach ($form_state['values']['files'] as $fid => $file) {
      // If the node was previewed prior to saving, $form['#node']->files[$fid]
      // is an array instead of an object. Convert file to object for compatibility.
      $form['#node']->files[$fid] = (object) $form['#node']->files[$fid];
      $form_state['values']['files'][$fid]['new'] = !empty($form['#node']->files[$fid]->new);
    }
  }

  // Order the form according to the set file weight values.
  if (!empty($form_state['values']['files'])) {
    $microweight = 0.001;
    foreach ($form_state['values']['files'] as $fid => $file) {
      if (is_numeric($fid)) {
        $form_state['values']['files'][$fid]['#weight'] = $file['weight'] + $microweight;
        $microweight += 0.001;
      }
    }
    uasort($form_state['values']['files'], 'element_sort');
  }
}