Projet

Général

Profil

Paste
Télécharger (2,73 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / bootstrap / templates / system / textfield.func.php @ 388c412d

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

    
7
/**
8
 * Returns HTML for a textfield form element.
9
 *
10
 * @param array $variables
11
 *   An associative array containing:
12
 *   - element: An associative array containing the properties of the element.
13
 *     Properties used: #title, #value, #description, #size, #maxlength,
14
 *     #required, #attributes, #autocomplete_path.
15
 *
16
 * @return string
17
 *   The constructed HTML.
18
 *
19
 * @see theme_textfield()
20
 *
21
 * @ingroup theme_functions
22
 */
23
function bootstrap_textfield($variables) {
24
  $element = $variables['element'];
25
  $element['#attributes']['type'] = 'text';
26
  element_set_attributes($element, array(
27
    'id',
28
    'name',
29
    'value',
30
    'size',
31
    'maxlength',
32
  ));
33
  _form_set_class($element, array('form-text'));
34

    
35
  $output = '<input' . drupal_attributes($element['#attributes']) . ' />';
36

    
37
  if ($element['#autocomplete_path'] && !empty($element['#autocomplete_input'])) {
38
    drupal_add_library('system', 'drupal.autocomplete');
39
    $element['#attributes']['class'][] = 'form-autocomplete';
40

    
41
    // Append a hidden autocomplete element.
42
    $autocomplete = array(
43
      '#type' => 'hidden',
44
      '#value' => $element['#autocomplete_input']['#url_value'],
45
      '#attributes' => array(
46
        'class' => array('autocomplete'),
47
        'disabled' => 'disabled',
48
        'id' => $element['#autocomplete_input']['#id'],
49
      ),
50
    );
51
    $output .= drupal_render($autocomplete);
52

    
53
    // Append icon for autocomplete "throbber" or use core's default throbber
54
    // whose background image must be set here because sites may not be
55
    // at the root of the domain (ie: /) and this value cannot be set via CSS.
56
    if (!isset($element['#autocomplete_icon'])) {
57
      $element['#autocomplete_icon'] = _bootstrap_icon('refresh', '<span class="autocomplete-throbber" style="background-image:url(' . file_create_url('misc/throbber.gif') . ')"></span>');
58
    }
59

    
60
    // Only add an icon if there is one.
61
    if ($element['#autocomplete_icon']) {
62
      $output .= '<span class="input-group-addon">' . $element['#autocomplete_icon'] . '</span>';
63

    
64
      // Wrap entire element in a input group if not already in one.
65
      if (!isset($element['#input_group']) && !isset($element['#input_group_button'])) {
66
        $input_group_attributes = isset($element['#input_group_attributes']) ? $element['#input_group_attributes'] : array();
67
        if (!isset($input_group_attributes['class'])) {
68
          $input_group_attributes['class'] = array();
69
        }
70
        if (!in_array('input-group', $input_group_attributes['class'])) {
71
          $input_group_attributes['class'][] = 'input-group';
72
        }
73
        $output = '<div' . drupal_attributes($input_group_attributes) . '>' . $output . '</div>';
74
      }
75
    }
76
  }
77

    
78
  return $output;
79
}