button.vars.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * @file
  4. * Stub file for "button" theme hook [pre]process functions.
  5. */
  6. /**
  7. * Pre-processes variables for the "button" theme hook.
  8. *
  9. * See theme function for list of available variables.
  10. *
  11. * @see bootstrap_button()
  12. * @see theme_button()
  13. *
  14. * @ingroup theme_preprocess
  15. */
  16. function bootstrap_preprocess_button(&$vars) {
  17. $element = &$vars['element'];
  18. // Drupal buttons should be of type 'submit'.
  19. // @see https://www.drupal.org/node/2540452
  20. $element['#attributes']['type'] = 'submit';
  21. // Set the element's other attributes.
  22. element_set_attributes($element, array('id', 'name', 'value'));
  23. // Add the base Bootstrap button class.
  24. $element['#attributes']['class'][] = 'btn';
  25. // Add button size, if necessary.
  26. if ($size = bootstrap_setting('button_size')) {
  27. $element['#attributes']['class'][] = $size;
  28. }
  29. // Colorize button.
  30. _bootstrap_colorize_button($element);
  31. // Add in the button type class.
  32. $element['#attributes']['class'][] = 'form-' . $element['#button_type'];
  33. // Ensure that all classes are unique, no need for duplicates.
  34. $element['#attributes']['class'] = array_unique($element['#attributes']['class']);
  35. }