webform-element.vars.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * @file
  4. * Stub file for "webform_element" theme hook [pre]process functions.
  5. */
  6. /**
  7. * Pre-processes variables for the "webform_element" theme hook.
  8. *
  9. * See theme function for list of available variables.
  10. *
  11. * @param array $variables
  12. * An associative array of variables, passed by reference.
  13. *
  14. * @see theme_webform_element()
  15. *
  16. * @ingroup theme_preprocess
  17. */
  18. function bootstrap_preprocess_webform_element(array &$variables) {
  19. $element = $variables['element'];
  20. $wrapper_attributes = array();
  21. if (isset($element['#wrapper_attributes'])) {
  22. $wrapper_attributes = $element['#wrapper_attributes'];
  23. }
  24. // See https://getbootstrap.com/docs/3.4/css/#forms-controls.
  25. if (isset($element['#type'])) {
  26. if ($element['#type'] === 'radio') {
  27. $wrapper_attributes['class'][] = 'radio';
  28. }
  29. elseif ($element['#type'] === 'checkbox') {
  30. $wrapper_attributes['class'][] = 'checkbox';
  31. }
  32. elseif ($element['#type'] !== 'hidden') {
  33. $wrapper_attributes['class'][] = 'form-group';
  34. }
  35. }
  36. $variables['element']['#wrapper_attributes'] = $wrapper_attributes;
  37. }