file-managed-file.func.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @file
  4. * Stub file for bootstrap_file_managed_file().
  5. */
  6. /**
  7. * Returns HTML for a managed file element.
  8. *
  9. * @param array $variables
  10. * An associative array containing:
  11. * - element: A render element representing the file.
  12. *
  13. * @return string
  14. * The constructed HTML.
  15. *
  16. * @see theme_file_managed_file()
  17. *
  18. * @ingroup theme_functions
  19. */
  20. function bootstrap_file_managed_file($variables) {
  21. $output = '';
  22. $element = $variables['element'];
  23. $attributes = array();
  24. if (isset($element['#id'])) {
  25. $attributes['id'] = $element['#id'];
  26. }
  27. if (!empty($element['#attributes']['class'])) {
  28. $attributes['class'] = (array) $element['#attributes']['class'];
  29. }
  30. $attributes['class'][] = 'form-managed-file';
  31. $attributes['class'][] = 'input-group';
  32. $element['upload_button']['#attributes']['class'][] = 'btn-primary';
  33. $element['upload_button']['#prefix'] = '<span class="input-group-btn">';
  34. $element['upload_button']['#suffix'] = '</span>';
  35. $element['remove_button']['#prefix'] = '<span class="input-group-btn">';
  36. $element['remove_button']['#suffix'] = '</span>';
  37. $element['remove_button']['#attributes']['class'][] = 'btn-danger';
  38. if (!empty($element['filename'])) {
  39. $element['filename']['#prefix'] = '<div class="form-control">';
  40. $element['filename']['#suffix'] = '</div>';
  41. }
  42. // This wrapper is required to apply JS behaviors and CSS styling.
  43. $output .= '<div' . drupal_attributes($attributes) . '>';
  44. // Immediately render hidden elements before the rest of the output.
  45. // The uploadprogress extension requires that the hidden identifier input
  46. // element appears before the file input element. They must also be siblings
  47. // inside the same parent element.
  48. // @see https://www.drupal.org/node/2155419
  49. foreach (element_children($element) as $child) {
  50. if (isset($element[$child]['#type']) && $element[$child]['#type'] === 'hidden') {
  51. $output .= drupal_render($element[$child]);
  52. }
  53. }
  54. // Render the rest of the element.
  55. $output .= drupal_render_children($element);
  56. $output .= '</div>';
  57. return $output;
  58. }