You are here

function node_gallery_edit_images_form in Node Gallery 6

Same name and namespace in other branches
  1. 6.2 node_gallery.pages.inc \node_gallery_edit_images_form()
1 call to node_gallery_edit_images_form()
node_gallery_upload_js 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 197
Node gallery pages.

Code

function node_gallery_edit_images_form($form_state, $gallery) {
  global $user;
  $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.
  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,
  );
  $form['gid'] = array(
    '#type' => 'value',
    '#value' => $gallery->nid,
  );
  $form['#config'] = $gallery
    ->get_config();
  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' => 'value',
        '#value' => $gallery->nid,
      );

      //get the required fields for image node edit and saving.
      $file->type = empty($file->type) ? $gallery
        ->get_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($file, $gallery
        ->get_config());
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#weight' => 20,
    //need this because this form is used in image upload ahah also.
    '#submit' => array(
      'node_gallery_images_edit_submit',
    ),
  );
  return $form;
}