Projet

Général

Profil

Paste
Télécharger (2,92 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / media / modules / media_bulk_upload / includes / media_bulk_upload.pages.inc @ 3115e37e

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
  // Improve the display of each file form.
31
  foreach (element_children($form['multiform']) as $key) {
32
    $fid = $form['multiform'][$key]['fid']['#value'];
33
    $file = $files[$fid];
34

    
35
    // Add the filename to each 'subform'.
36
    $title = t('<em>Edit @type</em> @title', array('@type' => $file->type, '@title' => $file->filename));
37
    $form['multiform'][$key]['#prefix'] = '<h2>' . $title . '</h2>';
38

    
39
    // Remove the 'replace file' functionality.
40
    $form['multiform'][$key]['replace_upload']['#access'] = FALSE;
41
    $form['multiform'][$key]['replace_keep_original_filename']['#access'] = FALSE;
42

    
43
    // Remove any actions.
44
    $form['multiform'][$key]['actions']['#access'] = FALSE;
45

    
46
    // Hide additional settings under a collapsible fieldset.
47
    $form['multiform'][$key]['settings'] = array(
48
      '#type' => 'fieldset',
49
      '#title' => t('Additional settings'),
50
      '#weight' => 99,
51
      '#collapsible' => TRUE,
52
      '#collapsed' => TRUE,
53
      // FAPI #collapsed and #collapsible not available in a render array.
54
      '#attached' => array(
55
        'js' => array(
56
          'misc/form.js',
57
          'misc/collapse.js',
58
        ),
59
      ),
60
      '#attributes' => array(
61
        'class' => array('collapsible', 'collapsed'),
62
      ),
63
    );
64

    
65
    $form['multiform'][$key]['settings']['additional_settings'] = $form['multiform'][$key]['additional_settings'];
66
    unset($form['multiform'][$key]['additional_settings']);
67
  }
68

    
69
  if (isset($form['buttons']['Delete'])) {
70
    $form['buttons']['Delete']['#access'] = FALSE;
71
  }
72

    
73
  // Add a cancel button at the bottom of the form.
74
  $form['buttons']['cancel'] = array(
75
    '#type' => 'link',
76
    '#title' => t('Cancel'),
77
    '#weight' => 50,
78
  );
79
  if (isset($_GET['destination'])) {
80
    $form['buttons']['cancel']['#href'] = $_GET['destination'];
81
  }
82
  else if (user_access('administer files')) {
83
    $form['buttons']['cancel']['#href'] = 'admin/content/file';
84
  }
85
  else {
86
    $form['buttons']['cancel']['#href'] = '<front>';
87
  }
88

    
89
  // Override the page title since each file form sets a title.
90
  drupal_set_title(t('Edit multiple files'));
91

    
92
  // Allow other modules to alter the form.
93
  drupal_alter('media_bulk_upload_edit_multiple_form', $form);
94

    
95
  return $form;
96
}