You are here

function node_gallery_api_sort_items_form in Node Gallery 7

Form function for the "Sort Items" tab.

1 string reference to 'node_gallery_api_sort_items_form'
node_gallery_api_menu in ./node_gallery_api.module
Implements hook_menu().

File

./node_gallery_api.pages.inc, line 26
Node Gallery module.

Code

function node_gallery_api_sort_items_form($form, $form_state, $gallery, $no_jquery = FALSE) {

  // node_gallery_set_user_breadcrumb($gallery->uid, $gallery);
  $form = array();
  $form['#images'] = array();
  $images = node_gallery_api_get_items($gallery, TRUE, FALSE);
  $image_count = count($images);
  $max_image_count = variable_get('node_gallery_sort_images_max', 750);
  if ($image_count > $max_image_count) {
    if (user_access(NODE_GALLERY_PERM_ADMIN_GALLERY)) {
      drupal_set_message(t('There are too many images in this gallery to display.
      You can increase the limit on !settings. The current limit is @max.', array(
        '!settings' => l(t('the Node Gallery settings page'), 'admin/config/content/node-gallery/settings'),
        '@max' => $max_image_count,
      )), 'warning');
    }
    else {

      // Don't show the admin link when you can't go there.
      drupal_set_message(t('There are too many images in this gallery to display. The current limit is @max.', array(
        '@max' => $max_image_count,
      )), 'warning');
    }
    return $form;
  }

  // Form generation starts here.
  $original_sort = array();
  for ($i = 0; $i < $image_count; ++$i) {
    $image = $images[$i];
    $original_sort[] = $image->nid;

    // @todo: We should document how many images will exhaust 128M RAM
    // to manage expectations.  I don't think there's
    // anything we can do here, because it's Drupals' form
    // render process that eats up the heap.
    $form['images-sort-' . $i] = array(
      '#type' => 'weight',
      '#delta' => $image_count,
      '#default_value' => $i,
      '#attributes' => array(
        'class' => array(
          'sort',
        ),
      ),
    );
    $form['#images'][] = array(
      'nid' => $image->nid,
      'title' => check_plain($image->title),
      'created' => $image->created,
      'changed' => $image->changed,
      'status' => $image->status,
      'original_sort' => $i,
      'filepath' => isset($image->node_gallery['item_file_url']) ? $image->node_gallery['item_file_url'] : NULL,
      'file_object' => isset($image->node_gallery['item_file']) ? $image->node_gallery['item_file'] : NULL,
    );
    if (variable_get('node_gallery_api_display_exif_creation_date', FALSE)) {
      $form['#images'][$i]['exif_created'] = node_gallery_api_original_datetime_from_exif($image);
    }
  }
  $original_sort = implode($original_sort, ',');
  $form['original_sort'] = array(
    '#type' => 'hidden',
    '#value' => $original_sort,
  );
  $form['new_sort'] = array(
    '#type' => 'hidden',
    '#default_value' => $original_sort,
  );
  $form['ngid'] = array(
    '#type' => 'value',
    '#value' => $gallery->nid,
  );
  $form['gallery_type'] = array(
    '#type' => 'value',
    '#value' => $gallery->type,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save custom sorting'),
  );
  if (variable_get('node_gallery_api_activate_chronological_sorting_button', FALSE)) {
    $form['chronological_sort'] = array(
      '#type' => 'submit',
      '#value' => t('Set in chronological order'),
      '#submit' => array(
        'node_gallery_api_sort_items_form_set_chronological_sorting',
      ),
    );
  }
  $form['remove'] = array(
    '#type' => 'submit',
    '#value' => t('Restore default sorting'),
    '#submit' => array(
      'node_gallery_api_sort_items_form_remove_weights_submit',
    ),
  );
  return $form;
}