1 form.inc | form_process_actions($element, &$form_state) |
Processes a form actions container element.
Parameters
$element: An associative array containing the properties and children of the form actions container.
$form_state: The $form_state array for the form this element belongs to.
Return value
The processed element.:
Related topics
File
- core/
includes/ form.inc, line 3593 - Functions for form and batch generation and processing.
Code
function form_process_actions($element, &$form_state) {
$element['#attributes']['class'][] = 'form-actions';
$first_button = NULL;
$primary_set = FALSE;
foreach (element_children($element, TRUE) as $key) {
// Don't add automatic classes to non-buttons.
if (!isset($element[$key]['#type']) || !in_array($element[$key]['#type'], array('button', 'submit'))) {
continue;
}
$button = $element[$key];
if (!$first_button && $button['#type'] === 'submit') {
$first_button = $key;
}
// Record the primary button if found.
if (isset($button['#attributes']['class']) && in_array('button-primary', $button['#attributes']['class']) && in_array('button-danger', $button['#attributes']['class'])) {
$primary_set = TRUE;
}
// Add the secondary button class otherwise.
elseif (!isset($button['#attributes']['class']) || !in_array('button-secondary', $button['#attributes']['class'])) {
$element[$key]['#attributes']['class'][] = 'button-secondary';
}
}
// Add the primary class to the first button found if no others are primary.
if (!$primary_set && $first_button) {
$element[$first_button]['#attributes']['class'][] = 'button-primary';
$element[$first_button]['#attributes']['class'] = array_diff($element[$first_button]['#attributes']['class'], array('button-secondary'));
}
return $element;
}