container.func.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * @file
  4. * Stub file for bootstrap_container().
  5. */
  6. /**
  7. * Returns HTML to wrap child elements in a container.
  8. *
  9. * Used for grouped form items. Can also be used as a #theme_wrapper for any
  10. * renderable element, to surround it with a <div> and add attributes such as
  11. * classes or an HTML id.
  12. *
  13. * @param array $variables
  14. * An associative array containing:
  15. * - element: An associative array containing the properties of the element.
  16. * Properties used: #id, #attributes, #children.
  17. *
  18. * @return string
  19. * The constructed HTML.
  20. *
  21. * @see theme_container()
  22. *
  23. * @ingroup theme_functions
  24. */
  25. function bootstrap_container(array $variables) {
  26. $element = $variables['element'];
  27. // Ensure #attributes is set.
  28. $element += array('#attributes' => array());
  29. // Special handling for form elements.
  30. if (isset($element['#array_parents'])) {
  31. // Assign an html ID.
  32. if (!isset($element['#attributes']['id'])) {
  33. $element['#attributes']['id'] = $element['#id'];
  34. }
  35. // Core's "form-wrapper" class is required for states.js to function.
  36. $element['#attributes']['class'][] = 'form-wrapper';
  37. // Add Bootstrap "form-group" class.
  38. if (!isset($element['#form_group']) || !!$element['#form_group']) {
  39. $element['#attributes']['class'][] = 'form-group';
  40. }
  41. }
  42. return '<div' . drupal_attributes($element['#attributes']) . '>' . $element['#children'] . '</div>';
  43. }