1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Common pages for the Media Bulk Upload module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Menu callback; Edit multiple files on the same page using multiform module.
|
10
|
*
|
11
|
* @todo When http://drupal.org/node/1227706 is fixed, filter the $files
|
12
|
* array using file_access($file, 'edit').
|
13
|
*
|
14
|
* @see media_bulk_upload_file_operation_edit_multiple()
|
15
|
*/
|
16
|
function media_bulk_upload_file_page_edit_multiple($files) {
|
17
|
if (empty($files)) {
|
18
|
return MENU_ACCESS_DENIED;
|
19
|
}
|
20
|
|
21
|
$forms = array();
|
22
|
foreach ($files as $file) {
|
23
|
// To maintain unique form_ids, append the file id.
|
24
|
$forms[] = array('media_edit_' . $file->fid, $file);
|
25
|
}
|
26
|
|
27
|
$form = call_user_func_array('multiform_get_form', $forms);
|
28
|
$form['#attributes']['class'][] = 'media-bulk-upload-multiedit-form';
|
29
|
|
30
|
// Add the title to each 'subform'.
|
31
|
foreach (element_children($form['multiform']) as $key) {
|
32
|
$fid = $form['multiform'][$key]['fid']['#value'];
|
33
|
$file = $files[$fid];
|
34
|
$title = t('<em>Edit @type</em> @title', array('@type' => $file->type, '@title' => $file->filename));
|
35
|
$form['multiform'][$key]['#prefix'] = '<h2>' . $title . '</h2>';
|
36
|
$form['multiform'][$key]['actions']['#access'] = FALSE;
|
37
|
}
|
38
|
|
39
|
if (isset($form['buttons']['Delete'])) {
|
40
|
$form['buttons']['Delete']['#access'] = FALSE;
|
41
|
}
|
42
|
|
43
|
// Add a cancel button at the bottom of the form.
|
44
|
$form['buttons']['cancel'] = array(
|
45
|
'#type' => 'link',
|
46
|
'#title' => t('Cancel'),
|
47
|
'#weight' => 50,
|
48
|
);
|
49
|
if (isset($_GET['destination'])) {
|
50
|
$form['buttons']['cancel']['#href'] = $_GET['destination'];
|
51
|
}
|
52
|
else if (user_access('administer files')) {
|
53
|
$form['buttons']['cancel']['#href'] = 'admin/content/file';
|
54
|
}
|
55
|
else {
|
56
|
$form['buttons']['cancel']['#href'] = '<front>';
|
57
|
}
|
58
|
|
59
|
// Override the page title since each file form sets a title.
|
60
|
drupal_set_title(t('Edit multiple files'));
|
61
|
|
62
|
// Allow other modules to alter the form.
|
63
|
drupal_alter('media_bulk_upload_edit_multiple_form', $form);
|
64
|
|
65
|
return $form;
|
66
|
}
|