Last active
December 29, 2015 15:19
-
-
Save opdavies/7689563 to your computer and use it in GitHub Desktop.
Add classes to form actions in Drupal 7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_form_alter(). | |
*/ | |
function MYTHEME_form_alter(&$form) { | |
// Add additional classes to each form action. | |
if (isset($form['actions'])) { | |
$actions = element_children($form['actions']); | |
foreach ($actions as $action) { | |
$item = &$form['actions'][$action]; | |
// Add a generic "button" class. | |
$item['#attributes']['class'][] = 'button'; | |
// Add a type-specific "button-{type}" class (e.g. "button-submit"). | |
$item['#attributes']['class'][] = 'button-' . $action; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment