Categories
Drupal Development Resources

Undoing Drupal Bootstrap theme’s rewriting of buttons

Drupal Bootstrap replaces instances of input type=”submit” into buttons by default. This occasionally breaks other module functionality such as hierarchical select module. Rather than hack the bootstrap module we can declare our own theme_button() call in template.php which would override bootstrap’s bootstrap_button() modification.

Enter this in your subtheme’s template.php file and update “YOURTHEME” to your own theme name.

function YOURTHEME_button($variables) {
  $element = $variables['element'];
  $element['#attributes']['type'] = 'submit';
  element_set_attributes($element, array('id', 'name', 'value'));

  $element['#attributes']['class'][] = 'form-' . $element['#button_type'];
  if (!empty($element['#attributes']['disabled'])) {
    $element['#attributes']['class'][] = 'form-button-disabled';
  }

  return '<input' . drupal_attributes($element['#attributes']) . ' />';
}

This may break some default styles applied to the <button> selectors, so you may need to update your CSS accordingly.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.