1 |
ca0757b9
|
Assos Assos
|
<?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 |
2b3c8cc1
|
Assos Assos
|
// Improve the display of each file form.
|
31 |
ca0757b9
|
Assos Assos
|
foreach (element_children($form['multiform']) as $key) {
|
32 |
|
|
$fid = $form['multiform'][$key]['fid']['#value'];
|
33 |
|
|
$file = $files[$fid];
|
34 |
2b3c8cc1
|
Assos Assos
|
|
35 |
|
|
// Add the filename to each 'subform'.
|
36 |
ca0757b9
|
Assos Assos
|
$title = t('<em>Edit @type</em> @title', array('@type' => $file->type, '@title' => $file->filename));
|
37 |
|
|
$form['multiform'][$key]['#prefix'] = '<h2>' . $title . '</h2>';
|
38 |
2b3c8cc1
|
Assos Assos
|
|
39 |
|
|
// Remove the 'replace file' functionality.
|
40 |
|
|
$form['multiform'][$key]['replace_upload']['#access'] = FALSE;
|
41 |
|
|
|
42 |
|
|
// Remove any actions.
|
43 |
ca0757b9
|
Assos Assos
|
$form['multiform'][$key]['actions']['#access'] = FALSE;
|
44 |
2b3c8cc1
|
Assos Assos
|
|
45 |
|
|
// Hide additional settings under a collapsible fieldset.
|
46 |
|
|
$form['multiform'][$key]['settings'] = array(
|
47 |
|
|
'#type' => 'fieldset',
|
48 |
|
|
'#title' => t('Additional settings'),
|
49 |
|
|
'#weight' => 99,
|
50 |
|
|
'#collapsible' => TRUE,
|
51 |
|
|
'#collapsed' => TRUE,
|
52 |
|
|
// FAPI #collapsed and #collapsible not available in a render array.
|
53 |
|
|
'#attached' => array(
|
54 |
|
|
'js' => array(
|
55 |
|
|
'misc/form.js',
|
56 |
|
|
'misc/collapse.js',
|
57 |
|
|
),
|
58 |
|
|
),
|
59 |
|
|
'#attributes' => array(
|
60 |
|
|
'class' => array('collapsible', 'collapsed'),
|
61 |
|
|
),
|
62 |
|
|
);
|
63 |
|
|
|
64 |
|
|
$form['multiform'][$key]['settings']['additional_settings'] = $form['multiform'][$key]['additional_settings'];
|
65 |
|
|
unset($form['multiform'][$key]['additional_settings']);
|
66 |
ca0757b9
|
Assos Assos
|
}
|
67 |
|
|
|
68 |
|
|
if (isset($form['buttons']['Delete'])) {
|
69 |
|
|
$form['buttons']['Delete']['#access'] = FALSE;
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
// Add a cancel button at the bottom of the form.
|
73 |
|
|
$form['buttons']['cancel'] = array(
|
74 |
|
|
'#type' => 'link',
|
75 |
|
|
'#title' => t('Cancel'),
|
76 |
|
|
'#weight' => 50,
|
77 |
|
|
);
|
78 |
|
|
if (isset($_GET['destination'])) {
|
79 |
|
|
$form['buttons']['cancel']['#href'] = $_GET['destination'];
|
80 |
|
|
}
|
81 |
|
|
else if (user_access('administer files')) {
|
82 |
|
|
$form['buttons']['cancel']['#href'] = 'admin/content/file';
|
83 |
|
|
}
|
84 |
|
|
else {
|
85 |
|
|
$form['buttons']['cancel']['#href'] = '<front>';
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
// Override the page title since each file form sets a title.
|
89 |
|
|
drupal_set_title(t('Edit multiple files'));
|
90 |
|
|
|
91 |
|
|
// Allow other modules to alter the form.
|
92 |
|
|
drupal_alter('media_bulk_upload_edit_multiple_form', $form);
|
93 |
|
|
|
94 |
|
|
return $form;
|
95 |
|
|
} |