Projet

Général

Profil

Paste
Télécharger (3,91 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / bootstrap / templates / file / file-widget-multiple.func.php @ 4eeb3b46

1
<?php
2
/**
3
 * @file
4
 * Stub file for bootstrap_file_widget_multiple().
5
 */
6

    
7
/**
8
 * Returns HTML for a group of file upload widgets.
9
 *
10
 * @param array $variables
11
 *   An associative array containing:
12
 *   - element: A render element representing the widgets.
13
 *
14
 * @return string
15
 *   The constructed HTML.
16
 *
17
 * @see theme_file_widget_multiple()
18
 *
19
 * @ingroup theme_functions
20
 */
21
function bootstrap_file_widget_multiple($variables) {
22
  $element = $variables['element'];
23

    
24
  // Special ID and classes for draggable tables.
25
  $weight_class = $element['#id'] . '-weight';
26
  $table_id = $element['#id'] . '-table';
27

    
28
  // Build up a table of applicable fields.
29
  $headers = array();
30
  $headers[] = t('File information');
31
  if ($element['#display_field']) {
32
    $headers[] = array(
33
      'data' => t('Display'),
34
      'class' => array('checkbox'),
35
    );
36
  }
37
  $headers[] = t('Weight');
38
  $headers[] = t('Operations');
39

    
40
  // Get our list of widgets in order (needed when the form comes back after
41
  // preview or failed validation).
42
  $widgets = array();
43
  foreach (element_children($element) as $key) {
44
    $widgets[] = &$element[$key];
45
  }
46
  usort($widgets, '_field_sort_items_value_helper');
47

    
48
  $rows = array();
49
  foreach ($widgets as $key => &$widget) {
50
    // Save the uploading row for last.
51
    if (!isset($widget['#file']) || $widget['#file'] === FALSE) {
52
      $widget['#title'] = $element['#file_upload_title'];
53
      $widget['#description'] = $element['#file_upload_description'];
54
      continue;
55
    }
56

    
57
    // Delay rendering of the buttons, so that they can be rendered later in the
58
    // "operations" column.
59
    $operations_elements = array();
60
    foreach (element_children($widget) as $sub_key) {
61
      if (isset($widget[$sub_key]['#type']) && $widget[$sub_key]['#type'] == 'submit') {
62
        hide($widget[$sub_key]);
63
        $operations_elements[] = &$widget[$sub_key];
64
      }
65
    }
66

    
67
    // Delay rendering of the "Display" option and the weight selector, so that
68
    // each can be rendered later in its own column.
69
    if ($element['#display_field']) {
70
      hide($widget['display']);
71
    }
72
    hide($widget['_weight']);
73

    
74
    // Render everything else together in a column, without the normal wrappers.
75
    $widget['#theme_wrappers'] = array();
76
    $information = drupal_render($widget);
77

    
78
    // Render the previously hidden elements, using render() instead of
79
    // drupal_render(), to undo the earlier hide().
80
    $operations = '';
81
    foreach ($operations_elements as $operation_element) {
82
      $operation_element['#attributes']['class'][] = 'btn-xs';
83
      switch ($operation_element['#value']) {
84
        case t('Remove'):
85
          $operation_element['#icon'] = _bootstrap_icon('remove');
86
          break;
87
      }
88
      $operations .= render($operation_element);
89
    }
90
    $display = '';
91
    if ($element['#display_field']) {
92
      unset($widget['display']['#title']);
93
      $display = array(
94
        'data' => render($widget['display']),
95
        'class' => array('checkbox'),
96
      );
97
    }
98
    $widget['_weight']['#attributes']['class'] = array($weight_class);
99
    $weight = render($widget['_weight']);
100

    
101
    // Arrange the row with all of the rendered columns.
102
    $row = array();
103
    $row[] = $information;
104
    if ($element['#display_field']) {
105
      $row[] = $display;
106
    }
107
    $row[] = $weight;
108
    $row[] = $operations;
109
    $rows[] = array(
110
      'data' => $row,
111
      'class' => isset($widget['#attributes']['class']) ? array_merge($widget['#attributes']['class'], array('draggable')) : array('draggable'),
112
    );
113
  }
114

    
115
  drupal_add_tabledrag($table_id, 'order', 'sibling', $weight_class);
116

    
117
  $output = '';
118
  if (!empty($rows)) {
119
    $table = array(
120
      '#theme' => 'table',
121
      '#header' => $headers,
122
      '#rows' => $rows,
123
      '#attributes' => array(
124
        'id' => $table_id,
125
        'class' => array(
126
          'managed-files',
127
        ),
128
      ),
129
    );
130
    $output = drupal_render($table);
131
  }
132
  $output .= drupal_render_children($element);
133
  return $output;
134
}