You are here

function node_gallery_sort_images_form in Node Gallery 6.3

Same name and namespace in other branches
  1. 6.2 node_gallery.pages.inc \node_gallery_sort_images_form()

Form function for the "Sort Images" tab.

Parameters

$gallery: A populated node gallery object.

Return value

Form array.

1 string reference to 'node_gallery_sort_images_form'
node_gallery_menu in ./node_gallery.module
Implements hook_menu().

File

./node_gallery.pages.inc, line 730
Handles displaying of Node gallery pages.

Code

function node_gallery_sort_images_form($form_state, $gallery, $no_jquery = FALSE) {
  node_gallery_set_user_breadcrumb($gallery->uid, $gallery);
  $form = array();
  $form['#images'] = array();
  $images = node_gallery_get_images($gallery, TRUE, FALSE);
  $image_count = count($images);
  $jquery_ui_integration = FALSE;
  if (module_exists('jquery_ui') && variable_get('node_gallery_jquery_ui_integration', TRUE) && $no_jquery != 'no_jquery') {
    $jquery_ui_integration = TRUE;
  }
  $max_image_count = variable_get('node_gallery_sort_images_max', 750);
  if ($image_count > $max_image_count) {
    drupal_set_message(t('There are too many images in this gallery to display. You can increase the limit by !settings_url. The current limit is !max.', array(
      '!settings' => 'admin/settings/node_gallery/settings',
      '!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.
    if (!$jquery_ui_integration) {
      $form['images-sort-' . $i] = array(
        '#type' => 'weight',
        '#delta' => $image_count,
        '#default_value' => $i,
        '#attributes' => array(
          'class' => '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' => $image->filepath,
      'admin_thumb' => theme('imagecache', 'node-gallery-admin-thumbnail', $image->filepath, '', $image->title, array()),
    );
  }
  $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['gid'] = 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'),
  );
  $form['remove'] = array(
    '#type' => 'submit',
    '#value' => t('Restore default sorting'),
    '#submit' => array(
      'node_gallery_sort_images_form_remove_weights_submit',
    ),
  );
  $form['jquery_ui_integration'] = array(
    '#type' => 'value',
    '#value' => $jquery_ui_integration,
  );
  return $form;
}