';
// Add bootstrap class
- if (isset($element['#type']) && ($element['#type'] == "radio" || $element['#type'] == "checkbox")){
+ if (isset($element['#type']) && ($element['#type'] == 'radio' || $element['#type'] == 'checkbox')){
$exclude_control = TRUE;
}
else {
- $attributes['class'] = array('control-group');
+ $attributes['class'] = array('form-group');
}
// Check for errors and set correct error class
@@ -101,10 +98,21 @@ function bootstrap_form_element(&$variables) {
if (!empty($element['#name'])) {
$attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
}
+
// Add a class for disabled elements to facilitate cross-browser styling.
if (!empty($element['#attributes']['disabled'])) {
$attributes['class'][] = 'form-disabled';
}
+
+ // Add a class for checkbox elements.
+ if (!empty($element['#type']) && $element['#type'] == 'checkbox') {
+ $attributes['class'][] = 'checkbox';
+ }
+ // Add a class for radio elements.
+ if (!empty($element['#type']) && $element['#type'] == 'radio') {
+ $attributes['class'][] = 'radio';
+ }
+
$attributes['class'][] = 'form-item';
$output = '
' . "\n";
@@ -112,10 +120,17 @@ function bootstrap_form_element(&$variables) {
if (!isset($element['#title'])) {
$element['#title_display'] = 'none';
}
+
$prefix = isset($element['#field_prefix']) ? '
' . $element['#field_prefix'] . ' ' : '';
$suffix = isset($element['#field_suffix']) ? '
' . $element['#field_suffix'] . '' : '';
- // Prepare input whitelist - added to ensure ajax functions don't break
+ // File form elements need a prefix and suffix.
+ if ($element['#type'] == 'file') {
+ $prefix = '
' . $prefix;
+ $suffix = $suffix . '
';
+ }
+
+ // Prepare input whitelist - added to ensure that ajax functions don't break.
$whitelist = _bootstrap_element_whitelist();
switch ($element['#title_display']) {
@@ -128,13 +143,13 @@ function bootstrap_form_element(&$variables) {
$exclude_control = TRUE;
}
else {
- $output = $exclude_control ? $output : $output.$control_wrapper;
+ $output = $exclude_control ? $output : $output . $control_wrapper;
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
}
break;
case 'after':
- $output = $exclude_control ? $output : $output.$control_wrapper;
+ $output = $exclude_control ? $output : $output . $control_wrapper;
$variables['#children'] = ' ' . $prefix . $element['#children'] . $suffix;
$output .= ' ' . theme('form_element_label', $variables) . "\n";
break;
@@ -142,7 +157,7 @@ function bootstrap_form_element(&$variables) {
case 'none':
case 'attribute':
// Output no label and no required marker, only the children.
- $output = $exclude_control ? $output : $output.$control_wrapper;
+ $output = $exclude_control ? $output : $output . $control_wrapper;
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
break;
}
@@ -198,6 +213,17 @@ function bootstrap_form_element_label(&$variables) {
if ($element['#type'] != 'radio') {
$attributes['class'][] = 'control-label';
}
+
+ // If a radio or checkbox then remove the type class which we don't want.
+ // Should figure out what's adding these and stop it.
+ if ($element['#type'] == 'checkbox' || $element['#type'] == 'radio') {
+ foreach ($attributes['class'] as $index => $class) {
+ if ($class == 'checkbox' || $class == 'radio') {
+ unset($attributes['class'][$index]);
+ }
+ }
+ }
+
// @Bootstrap: Insert radio and checkboxes inside label elements.
$output = '';
if ( isset($variables['#children']) ) {
@@ -212,6 +238,50 @@ function bootstrap_form_element_label(&$variables) {
}
/**
+ * Returns HTML for a date element.
+ */
+function bootstrap_preprocess_date(&$vars) {
+ $vars['element']['#attributes']['class'][] ='form-inline';
+}
+
+/**
+ * Returns HTML for a managed file element.
+ */
+function bootstrap_preprocess_file_managed_file(&$vars) {
+ $vars['element']['#attributes']['class'][] = 'form-inline';
+ $vars['element']['upload']['#prefix'] = '
';
+ $vars['element']['upload']['#suffix'] = '
';
+}
+
+/**
+ * Returns HTML for a password element.
+ */
+function bootstrap_preprocess_password(&$vars) {
+ $vars['element']['#attributes']['class'][] ='form-control';
+}
+
+/**
+ * Returns HTML for a select element.
+ */
+function bootstrap_preprocess_select(&$vars) {
+ $vars['element']['#attributes']['class'][] ='form-control';
+}
+
+/**
+ * Returns HTML for a textfield element.
+ */
+function bootstrap_preprocess_textfield(&$vars) {
+ $vars['element']['#attributes']['class'][] ='form-control';
+}
+
+/**
+ * Returns HTML for a textarea element.
+ */
+function bootstrap_preprocess_textarea(&$vars) {
+ $vars['element']['#attributes']['class'][] ='form-control';
+}
+
+/**
* Preprocessor for theme('button').
*/
function bootstrap_preprocess_button(&$vars) {
@@ -314,13 +384,13 @@ function bootstrap_bootstrap_append_element(&$variables) {
}
$exclude_control = FALSE;
- $control_wrapper = '
';
+ $control_wrapper = '
';
// Add bootstrap class
- if ($element['#type'] == "radio" || $element['#type'] == "checkbox" || isset($element['#exclude_control'])) {
+ if ($element['#type'] == 'radio' || $element['#type'] == 'checkbox' || isset($element['#exclude_control'])) {
$exclude_control = TRUE;
}
else {
- $attributes['class'] = array('control-group');
+ $attributes['class'] = array('form-group');
}
// Check for errors and set correct error class
@@ -339,13 +409,8 @@ function bootstrap_bootstrap_append_element(&$variables) {
$attributes['class'][] = 'form-disabled';
}
-
- if (isset($element['#field_prefix'])) {
- $attributes['class'][] = 'input-prepend';
- }
-
- if (isset($element['#field_suffix'])) {
- $attributes['class'][] = 'input-append';
+ if (isset($element['#field_prefix']) || isset($element['#field_suffix'])) {
+ $attributes['class'][] = 'input-group';
}
$attributes['class'][] = 'form-item';
@@ -355,8 +420,8 @@ function bootstrap_bootstrap_append_element(&$variables) {
if (!isset($element['#title'])) {
$element['#title_display'] = 'none';
}
- $prefix = isset($element['#field_prefix']) ? $element['#field_prefix'] : '';
- $suffix = isset($element['#field_suffix']) ? $element['#field_suffix'] : '';
+ $prefix = isset($element['#field_prefix']) ? '' . $element['#field_prefix'] . '' : '';
+ $suffix = isset($element['#field_suffix']) ? '' . $element['#field_suffix'] . '' : '';
// Prepare input whitelist - added to ensure ajax functions don't break
$whitelist = _bootstrap_element_whitelist();
@@ -371,13 +436,13 @@ function bootstrap_bootstrap_append_element(&$variables) {
$exclude_control = TRUE;
}
else {
- $output = $exclude_control ? $output : $output.$control_wrapper;
+ $output = $exclude_control ? $output : $output . $control_wrapper;
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
}
break;
case 'after':
- $output = $exclude_control ? $output : $output.$control_wrapper;
+ $output = $exclude_control ? $output : $output . $control_wrapper;
$variables['#children'] = ' ' . $prefix . $element['#children'] . $suffix;
$output .= ' ' . theme('form_element_label', $variables) . "\n";
break;
@@ -385,7 +450,7 @@ function bootstrap_bootstrap_append_element(&$variables) {
case 'none':
case 'attribute':
// Output no label and no required marker, only the children.
- $output = $exclude_control ? $output : $output.$control_wrapper;
+ $output = $exclude_control ? $output : $output . $control_wrapper;
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
break;
}