Projet

Général

Profil

Paste
Télécharger (1,72 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / bootstrap / templates / file / file-widget.func.php @ 27370441

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

    
7
/**
8
 * Returns HTML for an individual file upload widget.
9
 *
10
 * @param array $variables
11
 *   An associative array containing:
12
 *   - element: A render element representing the widget.
13
 *
14
 * @return string
15
 *   The constructed HTML.
16
 *
17
 * @see theme_file_widget()
18
 *
19
 * @ingroup theme_functions
20
 */
21
function bootstrap_file_widget($variables) {
22
  $output = '';
23
  $element = $variables['element'];
24
  $element['upload_button']['#attributes']['class'][] = 'btn-primary';
25
  $element['upload_button']['#prefix'] = '<span class="input-group-btn">';
26
  $element['upload_button']['#suffix'] = '</span>';
27

    
28
  // The "form-managed-file" class is required for proper Ajax functionality.
29
  if (!empty($element['filename'])) {
30
    $output .= '<div class="file-widget form-managed-file clearfix">';
31
    // Add the file size after the file name.
32
    $element['filename']['#markup'] .= ' <span class="file-size badge">' . format_size($element['#file']->filesize) . '</span>';
33
  }
34
  else {
35
    $output .= '<div class="file-widget form-managed-file clearfix input-group">';
36
  }
37

    
38
  // Immediately render hidden elements before the rest of the output.
39
  // The uploadprogress extension requires that the hidden identifier input
40
  // element appears before the file input element. They must also be siblings
41
  // inside the same parent element.
42
  // @see https://www.drupal.org/node/2155419
43
  foreach (element_children($element) as $child) {
44
    if (isset($element[$child]['#type']) && $element[$child]['#type'] === 'hidden') {
45
      $output .= drupal_render($element[$child]);
46
    }
47
  }
48

    
49
  // Render the rest of the element.
50
  $output .= drupal_render_children($element);
51
  $output .= '</div>';
52
  return $output;
53
}