function media_library_modal_browse_form in Media Library 6
Utility to sub modules. This generates a form structure and add a pager for browsing media. This should be used in a modal context
Parameters
form_state - the form_state of the form: total - the total amount of results pager - boolean that indicates if the pager needs to be setup first
2 calls to media_library_modal_browse_form()
- ml_flickr_flickr_options_form in ml_image/
ml_flickr/ ml_flickr.module - Image selection stage
- ml_image_basic_existing_options_form in ml_image/
ml_image_basic/ ml_image_basic.module - Image selection stage
File
- ./
media_library.modal.inc, line 259 - Modal frame functions
Code
function media_library_modal_browse_form($form_state, $total = 0, $pager = TRUE) {
global $pager_page_array, $pager_total, $pager_total_items;
// Get variables
$limit = variable_get('media_library_limit', MEDIA_LIBRARY_LIMIT);
// Get total from pager_total_items
if (!$total) {
$total = $pager_total_items[0];
}
// Setup pager
if ($pager) {
$page = isset($_GET['page']) ? $_GET['page'] : 0;
$pages = ceil($total / $limit);
$pager_page_array = explode(',', $page);
$pager_total_items[0] = (int) $total;
$pager_total[0] = $pages;
$pager_page_array[0] = max(0, min((int) $pager_page_array[0], (int) $pager_total[0] - 1));
}
// Theme function
$form['#theme'] = 'media_library_browse_form';
// URL: A workaround from hell. Never caused any chaos, at least.
$type = $form_state['media_obj']->type;
$step = $form_state['step'];
$_GET['q'] = "media-library/main/add/{$type}/{$step}";
// Pager
$pager = '<div class="media-library-pager">' . theme('pager', array(), $limit, 0) . '</div>';
// This is a workaround, without it pager won't work.
// We must remove this from links so ctools response is adequate.
$pager = preg_replace('/ctools_multipart=1/', '', $pager);
$footer = theme('media_library_browse_footer', $total, $pages);
$form['#suffix'] = $footer . $pager;
return $form;
}