diff --git a/css/bootstrap-drupal.css b/css/bootstrap-drupal.css index b7fc6aa..7dfa785 100644 --- a/css/bootstrap-drupal.css +++ b/css/bootstrap-drupal.css @@ -30,7 +30,8 @@ z-index: 499; } -body.toolbar .navbar-fixed-top { +body.toolbar .navbar-fixed-top, +body.admin-menu .navbar-fixed-top { top: 30px; } diff --git a/includes/theme/form.inc b/includes/theme/form.inc index 1162aaf..6573e57 100644 --- a/includes/theme/form.inc +++ b/includes/theme/form.inc @@ -23,10 +23,10 @@ function bootstrap_button(&$vars) { } // @Bootstrap: Use appropriate bootstrap button types. - if ( strpos($element['#id'], 'submit') !== FALSE ) { + if ( isset($element['#id']) && strpos($element['#id'], 'submit') !== FALSE ) { $element['#attributes']['class'][] = 'btn-primary'; } - elseif ( strpos($element['#id'], 'delete') !== FALSE ) { + elseif ( isset($element['#id']) && strpos($element['#id'], 'delete') !== FALSE ) { $element['#attributes']['class'][] = 'btn-danger'; } @@ -47,9 +47,7 @@ function bootstrap_form(&$variables) { } // @Bootstrap: Switch forms to horizontal layout. - //$element['#horizontal'] = TRUE; - // Look for #horizontal property on form element. - if ( isset($element['#horizontal']) && $element['#horizontal'] ) { + if ( theme_get_setting('bootstrap_horizontal_forms') ) { $element['#attributes']['class'][] = 'form-horizontal'; } @@ -61,6 +59,10 @@ function bootstrap_form(&$variables) { * Returns HTML for a form element. */ function bootstrap_form_element(&$variables) { + // Check whether we have to introduce new divs that enable horizontal forms + // Icon add-ons, and validation hints. + $useBootstrapControlMarkup = theme_get_setting('bootstrap_horizontal_forms'); + $element = &$variables['element']; // This is also used in the installer, pre-database setup. $t = get_t(); @@ -77,13 +79,7 @@ function bootstrap_form_element(&$variables) { } // Add element's #type and #name as class to aid with JS/CSS selectors. - $attributes['class'] = array('control-group'); - - // Add an error class to the form wrapper. - if ( form_get_error($element) ) { - $attributes['class'][] = 'error'; - } - + $attributes['class'] = array('form-item'); if (!empty($element['#type'])) { $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-'); } @@ -94,6 +90,17 @@ function bootstrap_form_element(&$variables) { if (!empty($element['#attributes']['disabled'])) { $attributes['class'][] = 'form-disabled'; } + + $error = FALSE; + // @Bootstrap: Add an error class to the form wrapper. + if ( isset($element['#parents']) && $error = form_get_error($element) ) { + $attributes['class'][] = 'error'; + } + // @Bootstrap: Add Control Group if necessary + if($useBootstrapControlMarkup) { + $attributes['class'][] = 'control-group'; + } + $output = '' . "\n"; // If #title is not set, we don't display any label or required marker. @@ -107,12 +114,16 @@ function bootstrap_form_element(&$variables) { case 'before': case 'invisible': $output .= ' ' . theme('form_element_label', $variables); - $output .= '
'; + if($useBootstrapControlMarkup) { + $output .= '
'; + } $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n"; break; case 'after': - $output .= '
'; + if($useBootstrapControlMarkup) { + $output .= '
'; + } // @Bootstrap: Bootstrap markup requires the input element to be inside the label element. $variables['#children'] = ' ' . $prefix . $element['#children'] . $suffix; $output .= ' ' . theme('form_element_label', $variables) . "\n"; @@ -121,16 +132,26 @@ function bootstrap_form_element(&$variables) { case 'none': case 'attribute': // Output no label and no required marker, only the children. - $output .= '
'; + if($useBootstrapControlMarkup) { + $output .= '
'; + } $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n"; break; } + + if($useBootstrapControlMarkup) { + if($error) { + $output .= ''.$error.''; + } + $output .= '
'; + } if ( !empty($element['#description']) ) { - $output .= '

' . $element['#description'] . "

\n"; + $output .= '

' . $element['#description'] . "

\n"; } - $output .= "
\n"; + + $output .= "
\n"; return $output; } diff --git a/theme-settings.php b/theme-settings.php index 6b02a16..4afb046 100644 --- a/theme-settings.php +++ b/theme-settings.php @@ -92,4 +92,16 @@ function bootstrap_form_system_theme_settings_alter(&$form, $form_state) { '#size' => 5, '#maxlength' => 10, ); + + // Bootstrap Form settings + $form['forms'] = array( + '#type' => 'fieldset', + '#title' => t('Forms'), + ); + $form['forms']['bootstrap_horizontal_forms'] = array( + '#type' => 'checkbox', + '#title' => t('Use horizontal forms'), + '#description' => t('Caution: This setting introduces new elements in a form\'s DOM structure. It\'s possible that some modules relying on jQuery might not like it as the hierarchy changes.'), + '#default_value' => theme_get_setting('bootstrap_horizontal_forms'), + ); }