Add class to every buttons of standards forms

Public

Get raw version
php
  1. function THEME_OR_MODULE_preprocess_button(&$vars) {
  2. $vars['element']['#attributes']['class'][] = 'btn'; // Primary button class
  3.  
  4. if (isset($vars['element']['#value'])) {
  5. $classes = array(
  6. t('Submit') => 'btn-mini', // Only submit button's class
  7. t('Send') => 'btn-primary', // Only send button's class
  8. // ...
  9. );
  10. foreach ($classes as $search => $class) {
  11. if (strpos($vars['element']['#value'], $search) !== FALSE) {
  12. $vars['element']['#attributes']['class'][] = $class;
  13. break;
  14. }
  15. }
  16. }