Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion css/bootstrap-drupal.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
55 changes: 38 additions & 17 deletions includes/theme/form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand All @@ -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';
}

Expand All @@ -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();
Expand All @@ -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'], '_', '-');
}
Expand All @@ -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 = '<div' . drupal_attributes($attributes) . '>' . "\n";

// If #title is not set, we don't display any label or required marker.
Expand All @@ -107,12 +114,16 @@ function bootstrap_form_element(&$variables) {
case 'before':
case 'invisible':
$output .= ' ' . theme('form_element_label', $variables);
$output .= '<div class="controls">';
if($useBootstrapControlMarkup) {
$output .= '<div class="controls">';
}
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
break;

case 'after':
$output .= '<div class="controls">';
if($useBootstrapControlMarkup) {
$output .= '<div class="controls">';
}
// @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";
Expand All @@ -121,16 +132,26 @@ function bootstrap_form_element(&$variables) {
case 'none':
case 'attribute':
// Output no label and no required marker, only the children.
$output .= '<div class="controls">';
if($useBootstrapControlMarkup) {
$output .= '<div class="controls">';
}
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
break;
}

if($useBootstrapControlMarkup) {
if($error) {
$output .= '<span class="help-inline">'.$error.'</span>';
}
$output .= '</div>';
}

if ( !empty($element['#description']) ) {
$output .= '<p class="help-block">' . $element['#description'] . "</p>\n";
$output .= '<p class="description">' . $element['#description'] . "</p>\n";
}

$output .= "</div></div>\n";

$output .= "</div>\n";

return $output;
}
Expand Down
12 changes: 12 additions & 0 deletions theme-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);
}