Projet

Général

Profil

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

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

1
<?php
2

    
3
/**
4
 * @file
5
 * Stub file for bootstrap_file_widget_multiple().
6
 */
7

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

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

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

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

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

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

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

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

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

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

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

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