function node_gallery_manage_images_form in Node Gallery 6.3
Displays the content for our "Manage Images" tab, which is a VBO view.
Parameters
$form_state: Drupal $form_state array
$gallery: A populated node gallery object.
Return value
FAPI array
1 string reference to 'node_gallery_manage_images_form'
- node_gallery_menu in ./
node_gallery.module - Implements hook_menu().
File
- ./
node_gallery.pages.inc, line 169 - Handles displaying of Node gallery pages.
Code
function node_gallery_manage_images_form($form_state, $gallery) {
global $pager_page_array, $pager_total;
$relationship = node_gallery_get_relationship($gallery->type);
// we must set these globals, because we do not call pager_query.
$element = 0;
$pager_page_array = isset($_GET['page']) ? explode(',', $_GET['page']) : array();
if (empty($pager_page_array[$element])) {
$pager_page_array[$element] = 0;
}
$items_per_page = $relationship['settings']['manage_images_per_page'];
$form = array(
'#theme' => 'node_gallery_manage_images_form',
'#cache' => TRUE,
);
if ($relationship['settings']['manage_images_show_gallery_list']) {
$gallery_list = node_gallery_get_gallery_list($gallery->type, $gallery->uid);
}
$form['#description'] = t('Manage Images form.');
$form['#thumb_imagecache'] = 'node-gallery-admin-thumbnail';
$form['#gallery'] = $gallery;
$form['#programmed'] = TRUE;
$images = array();
if (isset($_SESSION['node_gallery_plupload_nids'][$gallery->nid])) {
$images = $_SESSION['node_gallery_plupload_nids'][$gallery->nid];
// We trim the $images array to a max length to prevent OOM's on the manage images form.
// There's just no easy way to do paging for just one visit to the manage images tab.
drupal_set_message(t('Current display is filtered to show only images just uploaded. Please refresh the page to display all images in the gallery.'), 'status');
$length = min(variable_get('node_gallery_plupload_manage_images_limit', 100), count($images));
$images = array_slice($images, 0, $length);
$chunks = array_chunk($images, count($images));
unset($_SESSION['node_gallery_plupload_nids'][$gallery->nid]);
}
else {
$images = node_gallery_get_image_nids($gallery->nid, TRUE, FALSE);
$chunks = array_chunk($images, $items_per_page);
$images = $chunks[$pager_page_array[$element]];
}
$pager_total[$element] = count($chunks);
$enable_rotation = FALSE;
if ($relationship['settings']['manage_images_enable_rotation'] && (imageapi_default_toolkit() != 'imageapi_gd' || function_exists("imagerotate"))) {
$enable_rotation = TRUE;
}
if (!empty($images)) {
$count = 0;
$form['images']['#tree'] = TRUE;
foreach ($images as $nid) {
$count++;
if ($count % 50 == 0) {
// Make sure we don't run out of memory by clearing the cache.
$image = node_load(NULL, NULL, TRUE);
}
$image = node_load($nid);
$options[$nid] = '';
$form['images'][$nid]['remove'] = array(
'#type' => 'checkbox',
'#default_value' => FALSE,
);
if ($enable_rotation) {
$form['images'][$nid]['rotate'] = array(
'#type' => 'radios',
'#options' => array(
0 => t('None'),
90 => t('90° CW'),
270 => t('90° CCW'),
180 => t('180°'),
),
'#default_value' => 0,
);
if (module_exists('jquery_ui')) {
// add a link to a jquery ui dialog with previews
$form['images'][$nid]['rotate']['#suffix'] = l(t('rotate'), '', array(
'fragment' => ' ',
'attributes' => array(
'class' => 'ng3-rotate-link',
'rel' => imagecache_create_path('node-gallery-thumbnail', $image->{$relationship['imagefield_name']}[0]['filepath']),
),
));
}
}
if ($relationship['settings']['manage_images_show_gallery_list']) {
$form['images'][$nid]['gid'] = array(
'#type' => 'select',
'#title' => t('Gallery'),
'#default_value' => $gallery->nid,
'#options' => $gallery_list,
);
}
else {
$form['images'][$nid]['gid'] = array(
'#type' => 'value',
'#value' => $gallery->nid,
);
}
$form['images'][$nid]['edit_form'] = node_gallery_image_item_edit_form($form_state['values']['images'][$nid]['edit_form'], $image, $relationship);
//Some CCK widgets need to have #field_info populated
if (!isset($form['#field_info'])) {
$form['#field_info'] = $form['images'][$nid]['edit_form']['#field_info'];
}
}
}
$cover_nid = $gallery->cover_image;
$form['is_cover'] = array(
'#type' => 'radios',
'#default_value' => $cover_nid,
'#options' => $options,
);
$form['pager'] = array(
'#value' => theme('pager', NULL, $items_per_page, $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_manage_images_submit',
),
'#validate' => array(
'node_gallery_manage_images_validate',
),
);
// OG hook_form_alter's the image node form and mucks up the breadcrumbs.
// Calling our function after we load the image forms fixes that.
node_gallery_set_user_breadcrumb($gallery->uid, $gallery);
return $form;
}