You are here

function node_gallery_edit_images_form in Node Gallery 6.2

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

File

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

Code

function node_gallery_edit_images_form($form_state, $gallery) {
  global $user;
  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),
  ));
  $form = array(
    '#theme' => 'gallery_edit_images_form',
    '#cache' => TRUE,
  );

  //if this is new upload, then fid is file id;

  //if this is edit images, then fid is node id;

  //but fid is just an identifier here, so needn't care it.
  if (!empty($gallery->images) && is_array($gallery->images)) {
    foreach ($gallery->images as $fid => $f) {
      $options[$fid] = '';
      if ($f->is_cover) {
        $cover_fid = $fid;
      }
    }
  }
  $form['is_cover'] = array(
    '#type' => 'radios',
    '#default_value' => $cover_fid,
    '#options' => $options,
  );

  //we need this to verify if image was updated later.
  $form['#gallery'] = $gallery;

  //for display in theme;
  $form['#thumb_imagecache'] = $gallery->config['image_size']['thumbnail'];
  if (user_access('administer nodes') || user_access('edit any ' . $gallery->type . ' content') || user_access('administer node gallery')) {
    $gallery_list = node_gallery_get_list($gallery->type);
  }
  else {
    $gallery_list = node_gallery_get_list($gallery->type, $user->uid);
  }
  if (!empty($gallery->images) && is_array($gallery->images)) {
    $form['files']['#tree'] = TRUE;
    foreach ($gallery->images as $key => $file) {
      $file = (object) $file;
      $form['files'][$key]['remove'] = array(
        '#type' => 'checkbox',
        '#default_value' => $file->remove,
      );
      $form['files'][$key]['weight'] = array(
        '#type' => 'weight',
        '#delta' => count($gallery->images),
        '#default_value' => $file->weight,
      );
      $form['files'][$key]['filename'] = array(
        '#type' => 'value',
        '#value' => $file->filename,
      );
      $form['files'][$key]['filepath'] = array(
        '#type' => 'value',
        '#value' => $file->filepath,
      );
      $form['files'][$key]['filemime'] = array(
        '#type' => 'value',
        '#value' => $file->filemime,
      );
      $form['files'][$key]['filesize'] = array(
        '#type' => 'value',
        '#value' => $file->filesize,
      );
      $form['files'][$key]['fid'] = array(
        '#type' => 'value',
        '#value' => $file->fid,
      );
      $form['files'][$key]['gid'] = array(
        '#type' => 'select',
        '#title' => 'Gallery',
        '#default_value' => $gallery->nid,
        '#options' => $gallery_list,
      );

      //get the required fields for image node edit and saving.
      $file->type = empty($file->type) ? $gallery->config['image_type'] : $file->type;
      $file->gid = empty($file->gid) ? $gallery->nid : $file->gid;
      $form['files'][$key]['edit_form'] = node_gallery_image_item_edit_form($form_state['values']['files'][$key]['edit_form'], $file, $gallery->config);

      //Some CCK widgets need to have #field_info populated
      if (!isset($form['#field_info'])) {
        $form['#field_info'] = $form['files'][$key]['edit_form']['#field_info'];
      }
    }
  }

  //pager if it exists;

  /* Using the pager appears to break the order of images
    $form['pager'] = array(
      '#value' => theme('pager', NULL, variable_get('node_images_page_number', 20), NODE_GALLERY_IMAGE_PAGER_ELEMENT),
    );
    */
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#weight' => 20,
    //need this because this form is used in image upload ahah also.
    '#submit' => array(
      'node_gallery_images_edit_submit',
    ),
    '#validate' => array(
      'node_gallery_images_edit_validate',
    ),
  );
  return $form;
}