file -managed-file.func.php

Stub file for bootstrap_file_managed_file().

  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(array $variables) {
  21. $output = '';
  22. $element = $variables['element'];
  23. $attributes = array();
  24. // For Webform use, do not add the id to the wrapper.
  25. if (isset($element['#id']) && empty($element['#webform_component'])) {
  26. $attributes['id'] = $element['#id'];
  27. }
  28. if (!empty($element['#attributes']['class'])) {
  29. $attributes['class'] = (array) $element['#attributes']['class'];
  30. }
  31. $attributes['class'][] = 'form-managed-file';
  32. $attributes['class'][] = 'input-group';
  33. $element['upload_button']['#attributes']['class'][] = 'btn-primary';
  34. $element['upload_button']['#prefix'] = '<span class="input-group-btn">';
  35. $element['upload_button']['#suffix'] = '</span>';
  36. $element['remove_button']['#prefix'] = '<span class="input-group-btn">';
  37. $element['remove_button']['#suffix'] = '</span>';
  38. $element['remove_button']['#attributes']['class'][] = 'btn-danger';
  39. if (!empty($element['filename'])) {
  40. $element['filename']['#prefix'] = '<div class="form-control">';
  41. $element['filename']['#suffix'] = '</div>';
  42. }
  43. // This wrapper is required to apply JS behaviors and CSS styling.
  44. $output .= '<div' . drupal_attributes($attributes) . '>';
  45. // Immediately render hidden elements before the rest of the output.
  46. // The uploadprogress extension requires that the hidden identifier input
  47. // element appears before the file input element. They must also be siblings
  48. // inside the same parent element.
  49. // @see https://www.drupal.org/node/2155419
  50. foreach (element_children($element) as $child) {
  51. if (isset($element[$child]['#type']) && $element[$child]['#type'] === 'hidden') {
  52. $output .= drupal_render($element[$child]);
  53. }
  54. }
  55. // Render the rest of the element.
  56. $output .= drupal_render_children($element);
  57. $output .= '</div>';
  58. return $output;
  59. }

Functions

Name Description
bootstrap_file_managed_file Returns HTML for a managed file element.