Projet

Général

Profil

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

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

1
<?php
2

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

    
8
/**
9
 * Returns HTML for help text based on file upload validators.
10
 *
11
 * @param array $variables
12
 *   An associative array containing:
13
 *   - description: The normal description for this field, specified by the
14
 *     user.
15
 *   - upload_validators: An array of upload validators as used in
16
 *     $element['#upload_validators'].
17
 *
18
 * @return string
19
 *   The constructed HTML.
20
 *
21
 * @see theme_file_upload_help()
22
 *
23
 * @ingroup theme_functions
24
 */
25
function bootstrap_file_upload_help(array $variables) {
26
  // If popover's are disabled, just theme this normally.
27
  if (!bootstrap_setting('popover_enabled')) {
28
    return theme_file_upload_help($variables);
29
  }
30

    
31
  $build = array();
32
  if (!empty($variables['description'])) {
33
    $build['description'] = array(
34
      '#markup' => $variables['description'] . '<br>',
35
    );
36
  }
37

    
38
  $descriptions = array();
39
  $upload_validators = $variables['upload_validators'];
40
  if (isset($upload_validators['file_validate_size'])) {
41
    $descriptions[] = t('Files must be less than !size.', array('!size' => '<strong>' . format_size($upload_validators['file_validate_size'][0]) . '</strong>'));
42
  }
43
  if (isset($upload_validators['file_validate_extensions'])) {
44
    $descriptions[] = t('Allowed file types: !extensions.', array('!extensions' => '<strong>' . check_plain($upload_validators['file_validate_extensions'][0]) . '</strong>'));
45
  }
46
  if (isset($upload_validators['file_validate_image_resolution'])) {
47
    $max = $upload_validators['file_validate_image_resolution'][0];
48
    $min = $upload_validators['file_validate_image_resolution'][1];
49
    if ($min && $max && $min == $max) {
50
      $descriptions[] = t('Images must be exactly !size pixels.', array('!size' => '<strong>' . $max . '</strong>'));
51
    }
52
    elseif ($min && $max) {
53
      $descriptions[] = t('Images must be between !min and !max pixels.', array('!min' => '<strong>' . $min . '</strong>', '!max' => '<strong>' . $max . '</strong>'));
54
    }
55
    elseif ($min) {
56
      $descriptions[] = t('Images must be larger than !min pixels.', array('!min' => '<strong>' . $min . '</strong>'));
57
    }
58
    elseif ($max) {
59
      $descriptions[] = t('Images must be smaller than !max pixels.', array('!max' => '<strong>' . $max . '</strong>'));
60
    }
61
  }
62

    
63
  if ($descriptions) {
64
    $id = drupal_html_id('upload-instructions');
65
    $build['instructions'] = array(
66
      '#theme' => 'link__file_upload_requirements',
67
      // @todo remove space between icon/text and fix via styling.
68
      '#text' => _bootstrap_icon('question-sign') . ' ' . t('More information'),
69
      '#path' => '#',
70
      '#options' => array(
71
        'attributes' => array(
72
          'data-toggle' => 'popover',
73
          'data-target' => "#$id",
74
          'data-html' => TRUE,
75
          'data-placement' => 'bottom',
76
          'data-title' => t('File requirements'),
77
        ),
78
        'html' => TRUE,
79
        'external' => TRUE,
80
      ),
81
    );
82
    $build['requirements'] = array(
83
      '#theme_wrappers' => array('container__file_upload_requirements'),
84
      '#attributes' => array(
85
        'id' => $id,
86
        'class' => array('element-invisible', 'help-block'),
87
      ),
88
    );
89
    $build['requirements']['validators'] = array(
90
      '#theme' => 'item_list__file_upload_requirements',
91
      '#items' => $descriptions,
92
    );
93
  }
94

    
95
  return drupal_render($build);
96
}