Projet

Général

Profil

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

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

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

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

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

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

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

    
94
  return drupal_render($build);
95
}