You are here

function node_gallery_upload_form in Node Gallery 6.2

Same name and namespace in other branches
  1. 6 node_gallery.pages.inc \node_gallery_upload_form()
1 string reference to 'node_gallery_upload_form'
node_gallery_menu in ./node_gallery.module
Implementation of hook_menu().

File

./node_gallery.pages.inc, line 76
Node gallery pages.

Code

function node_gallery_upload_form($form_state, $gallery) {
  drupal_set_breadcrumb(array(
    l(t('Home'), NULL),
    l(t('Galleries'), 'galleries'),
    l(t('!user\'s Galleries', array(
      '!user' => $gallery->name,
    )), 'galleries/' . $gallery->uid),
    l($gallery->title, 'node/' . $gallery->nid),
  ));
  if (empty($form_state['storage']['step'])) {
    $form_state['storage']['step'] = 1;
  }

  //just a mark for submit handler.
  $form['is_upload'] = array(
    '#type' => 'value',
    '#value' => TRUE,
  );
  switch ($form_state['storage']['step']) {
    case 1:
      $form_state['storage']['gallery'] = $gallery;
      $config = node_gallery_get_config($gallery->type);
      $form['#attributes']['enctype'] = 'multipart/form-data';
      $upload_number = is_numeric($config['number_uploads']) ? $config['number_uploads'] : 5;
      for ($i = 1; $i <= $upload_number; $i++) {
        $form['uploads-' . $i] = array(
          '#type' => 'file',
          '#title' => t('Please select an image'),
        );
      }
      $form['description'] = array(
        '#value' => node_gallery_upload_limits($config),
      );
      $form['next'] = array(
        '#type' => 'submit',
        '#value' => t('Submit Images'),
        '#weight' => 20,
      );
      break;
    case 2:
      drupal_add_tabledrag('upload-attachments', 'order', 'sibling', 'upload-weight');
      drupal_add_js('misc/autocomplete.js');

      //this is upload form, we don't want to show the node's existing images;
      unset($form_state['storage']['gallery']->images);
      $form['#node'] = $form_state['storage']['gallery'];

      // Handle new uploads, and merge tmp files into node-files.
      node_gallery_upload_images($form, $form_state);
      $form = node_gallery_edit_images_form($form_state, $form_state['storage']['gallery']);
      break;
  }
  return $form;
}