textfield.func.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @file
  4. * Stub file for bootstrap_textfield().
  5. */
  6. /**
  7. * Returns HTML for a textfield form element.
  8. *
  9. * @param array $variables
  10. * An associative array containing:
  11. * - element: An associative array containing the properties of the element.
  12. * Properties used: #title, #value, #description, #size, #maxlength,
  13. * #required, #attributes, #autocomplete_path.
  14. *
  15. * @return string
  16. * The constructed HTML.
  17. *
  18. * @see theme_textfield()
  19. *
  20. * @ingroup theme_functions
  21. */
  22. function bootstrap_textfield($variables) {
  23. $element = $variables['element'];
  24. $element['#attributes']['type'] = 'text';
  25. element_set_attributes($element, array(
  26. 'id',
  27. 'name',
  28. 'value',
  29. 'size',
  30. 'maxlength',
  31. ));
  32. _form_set_class($element, array('form-text'));
  33. $output = '<input' . drupal_attributes($element['#attributes']) . ' />';
  34. $extra = '';
  35. if ($element['#autocomplete_path'] && !empty($element['#autocomplete_input'])) {
  36. drupal_add_library('system', 'drupal.autocomplete');
  37. $element['#attributes']['class'][] = 'form-autocomplete';
  38. $attributes = array();
  39. $attributes['type'] = 'hidden';
  40. $attributes['id'] = $element['#autocomplete_input']['#id'];
  41. $attributes['value'] = $element['#autocomplete_input']['#url_value'];
  42. $attributes['disabled'] = 'disabled';
  43. $attributes['class'][] = 'autocomplete';
  44. // Uses icon for autocomplete "throbber".
  45. if ($icon = _bootstrap_icon('refresh')) {
  46. $output = '<div class="input-group">' . $output . '<span class="input-group-addon">' . $icon . '</span></div>';
  47. }
  48. // Fallback to using core's throbber.
  49. else {
  50. $output = '<div class="input-group">' . $output . '<span class="input-group-addon">';
  51. // The throbber's background image must be set here because sites may not
  52. // be at the root of the domain (ie: /) and this value cannot be set via
  53. // CSS.
  54. $output .= '<span class="autocomplete-throbber" style="background-image:url(' . url('misc/throbber.gif') . ')"></span>';
  55. $output .= '</span></div>';
  56. }
  57. $extra = '<input' . drupal_attributes($attributes) . ' />';
  58. }
  59. return $output . $extra;
  60. }