/**
 * Overrides theme_form_element().
 */
function bootstrap_form_element(&$variables)
{
    $element =& $variables['element'];
    $is_checkbox = FALSE;
    $is_radio = FALSE;
    // This function is invoked as theme wrapper, but the rendered form element
    // may not necessarily have been processed by form_builder().
    $element += array('#title_display' => 'before');
    // Add element #id for #type 'item'.
    if (isset($element['#markup']) && !empty($element['#id'])) {
        $attributes['id'] = $element['#id'];
    }
    // Check for errors and set correct error class.
    if (isset($element['#parents']) && form_get_error($element)) {
        $attributes['class'][] = 'error';
    }
    if (!empty($element['#type'])) {
        $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
    }
    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';
    }
    if (!empty($element['#autocomplete_path']) && drupal_valid_path($element['#autocomplete_path'])) {
        $attributes['class'][] = 'form-autocomplete';
    }
    $attributes['class'][] = 'form-item';
    // See http://getbootstrap.com/css/#forms-controls.
    if (isset($element['#type'])) {
        if ($element['#type'] == "radio") {
            $attributes['class'][] = 'radio';
            $is_radio = TRUE;
        } elseif ($element['#type'] == "checkbox") {
            $attributes['class'][] = 'checkbox';
            $is_checkbox = TRUE;
        } else {
            $attributes['class'][] = 'form-group';
        }
    }
    $description = FALSE;
    $tooltip = FALSE;
    // Convert some descriptions to tooltips.
    // @see bootstrap_tooltip_descriptions setting in _bootstrap_settings_form()
    if (!empty($element['#description'])) {
        $description = $element['#description'];
        if (theme_get_setting('bootstrap_tooltip_enabled') && theme_get_setting('bootstrap_tooltip_descriptions') && $description === strip_tags($description) && strlen($description) <= 200) {
            $tooltip = TRUE;
            $attributes['data-toggle'] = 'tooltip';
            $attributes['title'] = $description;
        }
    }
    $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
    // If #title is not set, we don't display any label or required marker.
    if (!isset($element['#title'])) {
        $element['#title_display'] = 'none';
    }
    $prefix = '';
    $suffix = '';
    if (isset($element['#field_prefix']) || isset($element['#field_suffix'])) {
        // Determine if "#input_group" was specified.
        if (!empty($element['#input_group'])) {
            $prefix .= '<div class="input-group">';
            $prefix .= isset($element['#field_prefix']) ? '<span class="input-group-addon">' . $element['#field_prefix'] . '</span>' : '';
            $suffix .= isset($element['#field_suffix']) ? '<span class="input-group-addon">' . $element['#field_suffix'] . '</span>' : '';
            $suffix .= '</div>';
        } else {
            $prefix .= isset($element['#field_prefix']) ? $element['#field_prefix'] : '';
            $suffix .= isset($element['#field_suffix']) ? $element['#field_suffix'] : '';
        }
    }
    switch ($element['#title_display']) {
        case 'before':
        case 'invisible':
            $output .= ' ' . theme('form_element_label', $variables);
            $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
            break;
        case 'after':
            if ($is_radio || $is_checkbox) {
                $output .= ' ' . $prefix . $element['#children'] . $suffix;
            } else {
                $variables['#children'] = ' ' . $prefix . $element['#children'] . $suffix;
            }
            $output .= ' ' . theme('form_element_label', $variables) . "\n";
            break;
        case 'none':
        case 'attribute':
            // Output no label and no required marker, only the children.
            $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
            break;
    }
    if ($description && !$tooltip) {
        $output .= '<p class="help-block">' . $element['#description'] . "</p>\n";
    }
    $output .= "</div>\n";
    return $output;
}
Exemple #2
0
/**
 * Overrides theme_form_element().
 */
function europa_form_element(&$variables)
{
    $element =& $variables['element'];
    $is_checkbox = FALSE;
    $is_radio = FALSE;
    $feedback_message = FALSE;
    // This function is invoked as theme wrapper, but the rendered form element
    // may not necessarily have been processed by form_builder().
    $element += array('#title_display' => 'before');
    // Add element #id for #type 'item'.
    if (isset($element['#markup']) && !empty($element['#id'])) {
        $attributes['id'] = $element['#id'];
    }
    // Check for errors and set correct error class.
    if (isset($element['#parents']) && form_get_error($element)) {
        $attributes['class'][] = 'has-error';
        $feedback_message = '<p class="feedback-message is-error">' . form_get_error($element) . '</p>';
    }
    if (!empty($element['#type'])) {
        $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
    }
    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';
    }
    if (!empty($element['#autocomplete_path']) && drupal_valid_path($element['#autocomplete_path'])) {
        $attributes['class'][] = 'form-autocomplete';
    }
    $attributes['class'][] = 'form-item';
    // See http://getbootstrap.com/css/#forms-controls.
    if (isset($element['#type'])) {
        if ($element['#type'] == "radio") {
            $attributes['class'][] = 'radio';
            $is_radio = TRUE;
        } elseif ($element['#type'] == "checkbox") {
            $attributes['class'][] = 'checkbox';
            $is_checkbox = TRUE;
        } else {
            $attributes['class'][] = 'form-group';
        }
    }
    // Putting description into variable since it is not going to change.
    // Here Bootstrap tooltips have been removed since in current implemenation we
    // will use descriptions that are displayed under <label> element.
    if (!empty($element['#description'])) {
        $description = '<p class="help-block">' . $element['#description'] . '</p>';
    }
    $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
    // If #title is not set, we don't display any label or required marker.
    if (!isset($element['#title'])) {
        $element['#title_display'] = 'none';
    }
    $prefix = '';
    $suffix = '';
    if (isset($element['#field_prefix']) || isset($element['#field_suffix'])) {
        // Determine if "#input_group" was specified.
        if (!empty($element['#input_group'])) {
            $prefix .= '<div class="input-group">';
            $prefix .= isset($element['#field_prefix']) ? '<span class="input-group-addon">' . $element['#field_prefix'] . '</span>' : '';
            $suffix .= isset($element['#field_suffix']) ? '<span class="input-group-addon">' . $element['#field_suffix'] . '</span>' : '';
            $suffix .= '</div>';
        } else {
            $prefix .= isset($element['#field_prefix']) ? $element['#field_prefix'] : '';
            $suffix .= isset($element['#field_suffix']) ? $element['#field_suffix'] : '';
        }
    }
    switch ($element['#title_display']) {
        case 'before':
        case 'invisible':
            $output .= ' ' . theme('form_element_label', $variables);
            if (!empty($description)) {
                $output .= $description;
            }
            $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
            //if (form_get_error($element)) {
            $output .= $feedback_message;
            //}
            break;
        case 'after':
            if ($is_radio || $is_checkbox) {
                $output .= ' ' . $prefix . $element['#children'] . $suffix;
            } else {
                $variables['#children'] = ' ' . $prefix . $element['#children'] . $suffix;
            }
            $output .= ' ' . theme('form_element_label', $variables) . "\n";
            //if (form_get_error($element)) {
            $output .= $feedback_message;
            //}
            break;
        case 'none':
        case 'attribute':
            // Output no label and no required marker, only the children.
            if (!empty($description)) {
                $output .= $description;
            }
            $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
            //if (form_get_error($element)) {
            $output .= $feedback_message;
            //}
            break;
    }
    $output .= "</div>\n";
    return $output;
}
/**
 * Adds accessibility attributes.
 */
function govcms_zen_preprocess_aria_invalid(&$variables)
{
    if (!empty($variables['element']['#required']) && !drupal_installation_attempted()) {
        $variables['element']['#attributes']['required'] = 'true';
    }
    if (isset($variables['element']['#parents']) && form_get_error($variables['element']) !== NULL && !empty($variables['element']['#validated'])) {
        $variables['element']['#attributes']['aria-invalid'] = 'true';
    }
}
Exemple #4
0
/**
 * Implements theme_form_element().
 */
function progressive_sub_form_element(&$variables)
{
    $element =& $variables['element'];
    $is_checkbox = FALSE;
    $is_radio = FALSE;
    $element += array('#title_display' => 'before');
    if (isset($element['#markup']) && !empty($element['#id'])) {
        $attributes['id'] = $element['#id'];
    }
    if (isset($element['#parents']) && form_get_error($element)) {
        $attributes['class'][] = 'error';
    }
    if (!empty($element['#type'])) {
        $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
    }
    if (!empty($element['#name'])) {
        $attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
    }
    if (!empty($element['#attributes']['disabled'])) {
        $attributes['class'][] = 'form-disabled';
    }
    if (!empty($element['#autocomplete_path']) && drupal_valid_path($element['#autocomplete_path'])) {
        $attributes['class'][] = 'form-autocomplete';
    }
    $attributes['class'][] = 'form-item';
    if (isset($element['#type'])) {
        if ($element['#type'] == "radio") {
            $attributes['class'][] = 'radio';
            $is_radio = TRUE;
        } elseif ($element['#type'] == "checkbox") {
            $attributes['class'][] = 'checkbox';
            $is_checkbox = TRUE;
        } else {
            $attributes['class'][] = 'form-group';
        }
    }
    $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
    if (!isset($element['#title'])) {
        $element['#title_display'] = 'none';
    }
    $prefix = '';
    $suffix = '';
    if (isset($element['#field_prefix']) || isset($element['#field_suffix'])) {
        if (!empty($element['#input_group'])) {
            $prefix .= '<div class="input-group">';
            $prefix .= isset($element['#field_prefix']) ? '<span class="input-group-addon">' . $element['#field_prefix'] . '</span>' : '';
            $suffix .= isset($element['#field_suffix']) ? '<span class="input-group-addon">' . $element['#field_suffix'] . '</span>' : '';
            $suffix .= '</div>';
        } else {
            $prefix .= isset($element['#field_prefix']) ? $element['#field_prefix'] : '';
            $suffix .= isset($element['#field_suffix']) ? $element['#field_suffix'] : '';
        }
    }
    switch ($element['#title_display']) {
        case 'before':
        case 'invisible':
            $output .= ' ' . theme('form_element_label', $variables) . ' ' . $prefix . $element['#children'] . $suffix . "\n";
            break;
        case 'after':
            if ($is_radio || $is_checkbox) {
                $output .= ' ' . $prefix . $element['#children'] . $suffix;
            } else {
                $variables['#children'] = ' ' . $prefix . $element['#children'] . $suffix;
            }
            $output .= ' ' . theme('form_element_label', $variables) . "\n";
            break;
        case 'none':
        case 'attribute':
            $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
            break;
    }
    if (isset($element['#description'])) {
        $output .= '<p class="help-block">' . $element['#description'] . "</p>\n";
    }
    $output .= "</div>\n";
    return $output;
}
/**
 * Theme a webform time element.
 */
function stability_webform_time($variables)
{
    $element = $variables['element'];
    $element['hour']['#attributes']['class'][] = 'hour';
    $element['minute']['#attributes']['class'][] = 'minute';
    // Add error classes to all items within the element.
    if (form_get_error($element)) {
        $element['hour']['#attributes']['class'][] = 'error';
        $element['minute']['#attributes']['class'][] = 'error';
    }
    $output = '<div class="webform-container-inline row"><div class = "col-xs-2">' . drupal_render($element['hour']) . '</div><div class = "col-xs-3">' . drupal_render($element['minute']) . '</div><div class = "col-xs-2">' . drupal_render($element['ampm']) . '</div></div>';
    return $output;
}
Exemple #6
0
/**
 * Returns HTML for a form element.
 *
 * Each form element is wrapped in a DIV container having the following CSS
 * classes:
 * - form-item: Generic for all form elements.
 * - form-type-#type: The internal element #type.
 * - form-item-#name: The internal form element #name (usually derived from the
 *   $form structure and set via form_builder()).
 * - form-disabled: Only set if the form element is #disabled.
 *
 * In addition to the element itself, the DIV contains a label for the element
 * based on the optional #title_display property, and an optional #description.
 *
 * The optional #title_display property can have these values:
 * - before: The label is output before the element. This is the default.
 *   The label includes the #title and the required marker, if #required.
 * - after: The label is output after the element. For example, this is used
 *   for radio and checkbox #type elements as set in system_element_info().
 *   If the #title is empty but the field is #required, the label will
 *   contain only the required marker.
 * - invisible: Labels are critical for screen readers to enable them to
 *   properly navigate through forms but can be visually distracting. This
 *   property hides the label for everyone except screen readers.
 * - attribute: Set the title attribute on the element to create a tooltip
 *   but output no label element. This is supported only for checkboxes
 *   and radios in form_pre_render_conditional_form_element(). It is used
 *   where a visual label is not needed, such as a table of checkboxes where
 *   the row and column provide the context. The tooltip will include the
 *   title and required marker.
 *
 * If the #title property is not set, then the label and any required marker
 * will not be output, regardless of the #title_display or #required values.
 * This can be useful in cases such as the password_confirm element, which
 * creates children elements that have their own labels and required markers,
 * but the parent element should have neither. Use this carefully because a
 * field without an associated label can cause accessibility challenges.
 *
 * @param array $variables
 *   An associative array containing:
 *   - element: An associative array containing the properties of the element.
 *     Properties used: #title, #title_display, #description, #id, #required,
 *     #children, #type, #name.
 *
 * @return string
 *   The constructed HTML.
 *
 * @see theme_form_element()
 *
 * @ingroup theme_functions
 */
function bootstrap_form_element(&$variables)
{
    $element =& $variables['element'];
    $name = !empty($element['#name']) ? $element['#name'] : FALSE;
    $type = !empty($element['#type']) ? $element['#type'] : FALSE;
    $checkbox = $type && $type === 'checkbox';
    $radio = $type && $type === 'radio';
    // Create an attributes array for the wrapping container.
    if (empty($element['#wrapper_attributes'])) {
        $element['#wrapper_attributes'] = array();
    }
    $wrapper_attributes =& $element['#wrapper_attributes'];
    // This function is invoked as theme wrapper, but the rendered form element
    // may not necessarily have been processed by form_builder().
    $element += array('#title_display' => 'before');
    // Add wrapper ID for 'item' type.
    if ($type && $type === 'item' && !empty($element['#markup']) && !empty($element['#id'])) {
        $wrapper_attributes['id'] = $element['#id'];
    }
    // Check for errors and set correct error class.
    if (isset($element['#parents']) && form_get_error($element) || !empty($element['#required']) && bootstrap_setting('forms_required_has_error')) {
        $wrapper_attributes['class'][] = 'has-error';
    }
    // Add necessary classes to wrapper container.
    $wrapper_attributes['class'][] = 'form-item';
    if ($name) {
        $wrapper_attributes['class'][] = 'form-item-' . drupal_html_class($name);
    }
    if ($type) {
        $wrapper_attributes['class'][] = 'form-type-' . drupal_html_class($type);
    }
    if (!empty($element['#attributes']['disabled'])) {
        $wrapper_attributes['class'][] = 'form-disabled';
    }
    if (!empty($element['#autocomplete_path']) && drupal_valid_path($element['#autocomplete_path'])) {
        $wrapper_attributes['class'][] = 'form-autocomplete';
    }
    // Checkboxes and radios do no receive the 'form-group' class, instead they
    // simply have their own classes.
    if ($checkbox || $radio) {
        $wrapper_attributes['class'][] = drupal_html_class($type);
    } elseif ($type && $type !== 'hidden') {
        $wrapper_attributes['class'][] = 'form-group';
    }
    // Create a render array for the form element.
    $build = array('#theme_wrappers' => array('container__form_element'), '#attributes' => $wrapper_attributes);
    // Render the label for the form element.
    $build['label'] = array('#markup' => theme('form_element_label', $variables));
    // Increase the label weight if it should be displayed after the element.
    if ($element['#title_display'] === 'after') {
        $build['label']['#weight'] = 10;
    }
    // Checkboxes and radios render the input element inside the label. If the
    // element is neither of those, then the input element must be rendered here.
    if (!$checkbox && !$radio) {
        $prefix = isset($element['#field_prefix']) ? $element['#field_prefix'] : '';
        $suffix = isset($element['#field_suffix']) ? $element['#field_suffix'] : '';
        if ((!empty($prefix) || !empty($suffix)) && (!empty($element['#input_group']) || !empty($element['#input_group_button']))) {
            if (!empty($element['#field_prefix'])) {
                $prefix = '<span class="input-group-' . (!empty($element['#input_group_button']) ? 'btn' : 'addon') . '">' . $prefix . '</span>';
            }
            if (!empty($element['#field_suffix'])) {
                $suffix = '<span class="input-group-' . (!empty($element['#input_group_button']) ? 'btn' : 'addon') . '">' . $suffix . '</span>';
            }
            // Add a wrapping container around the elements.
            $input_group_attributes =& _bootstrap_get_attributes($element, 'input_group_attributes');
            $input_group_attributes['class'][] = 'input-group';
            $prefix = '<div' . drupal_attributes($input_group_attributes) . '>' . $prefix;
            $suffix .= '</div>';
        }
        // Build the form element.
        $build['element'] = array('#markup' => $element['#children'], '#prefix' => !empty($prefix) ? $prefix : NULL, '#suffix' => !empty($suffix) ? $suffix : NULL);
    }
    // Construct the element's description markup.
    if (!empty($element['#description'])) {
        $build['description'] = array('#type' => 'container', '#attributes' => array('class' => array('help-block')), '#weight' => 20, 0 => array('#markup' => filter_xss_admin($element['#description'])));
    }
    // Render the form element build array.
    return drupal_render($build);
}
function boostrapdrupal_form_element($variables)
{
    $element =& $variables['element'];
    $element += array('#title_display' => 'before');
    if (isset($element['#markup']) && !empty($element['#id'])) {
        $attributes['id'] = $element['#id'];
    }
    $attributes['class'] = array('form-item');
    if (!empty($element['#type'])) {
        $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
    }
    if (!empty($element['#name'])) {
        $attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
    }
    if (!empty($element['#attributes']['disabled'])) {
        $attributes['class'][] = 'form-disabled';
    }
    if (isset($element['#parents']) && form_get_error($element)) {
        $attributes['class'][] = 'has-error';
    }
    if ($element['#type'] != 'radio') {
        $attributes['class'][] = 'form-group';
    }
    $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
    if (!isset($element['#title'])) {
        $element['#title_display'] = 'none';
    }
    $prefix = isset($element['#field_prefix']) ? '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' : '';
    $suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>' : '';
    switch ($element['#title_display']) {
        case 'before':
        case 'invisible':
            $output .= ' ' . theme('form_element_label', $variables);
            $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
            break;
        case 'after':
            $output .= ' ' . $prefix . $element['#children'] . $suffix;
            $output .= ' ' . theme('form_element_label', $variables) . "\n";
            break;
        case 'none':
        case 'attribute':
            $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
            break;
    }
    if (!empty($element['#description'])) {
        $output .= '<div class="description">' . $element['#description'] . "</div>\n";
    }
    $output .= "</div>\n";
    return $output;
}
Exemple #8
0
/** Returns HTML for a form element.
---------------------------------------------------------- */
function megatron_form_element(&$variables)
{
    $element =& $variables['element'];
    // This is also used in the installer, pre-database setup.
    $t = get_t();
    // This function is invoked as theme wrapper, but the rendered form element
    // may not necessarily have been processed by form_builder().
    $element += array('#title_display' => 'before');
    // Add element #id for #type 'item'.
    if (isset($element['#markup']) && !empty($element['#id'])) {
        $attributes['id'] = $element['#id'];
    }
    // Add bootstrap class
    $attributes['class'] = array('control-group');
    // Check for errors and set correct error class
    if (isset($element['#parents']) && form_get_error($element)) {
        $attributes['class'][] = 'error';
    }
    if (!empty($element['#type'])) {
        $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
    }
    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';
    }
    $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
    // If #title is not set, we don't display any label or required marker.
    if (!isset($element['#title'])) {
        $element['#title_display'] = 'none';
    }
    $prefix = isset($element['#field_prefix']) ? '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' : '';
    $suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>' : '';
    switch ($element['#title_display']) {
        case 'before':
        case 'invisible':
            $output .= ' ' . theme('form_element_label', $variables);
            $output .= '<div class="controls">';
            $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
            break;
        case 'after':
            $output .= '<div class="controls">';
            $variables['#children'] = ' ' . $prefix . $element['#children'] . $suffix;
            $output .= ' ' . theme('form_element_label', $variables) . "\n";
            break;
        case 'none':
        case 'attribute':
            // Output no label and no required marker, only the children.
            $output .= '<div class="controls">';
            $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
            break;
    }
    if (!empty($element['#description'])) {
        $output .= '<p class="help-block">' . $element['#description'] . "</p>\n";
    }
    $output .= "</div></div>\n";
    return $output;
}
/**
 * Overrides theme_form_element().
 */
function bootstrap_form_element(&$variables)
{
    $element =& $variables['element'];
    $is_checkbox = FALSE;
    $is_radio = FALSE;
    // This function is invoked as theme wrapper, but the rendered form element
    // may not necessarily have been processed by form_builder().
    $element += array('#title_display' => 'before');
    // Add element #id for #type 'item'.
    if (isset($element['#markup']) && !empty($element['#id'])) {
        $attributes['id'] = $element['#id'];
    }
    // Check for errors and set correct error class.
    if (isset($element['#parents']) && form_get_error($element)) {
        $attributes['class'][] = 'error';
    }
    if (!empty($element['#type'])) {
        $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
    }
    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';
    }
    if (!empty($element['#autocomplete_path']) && drupal_valid_path($element['#autocomplete_path'])) {
        $attributes['class'][] = 'form-autocomplete';
    }
    $attributes['class'][] = 'form-item';
    // See http://getbootstrap.com/css/#forms-controls.
    if (isset($element['#type'])) {
        if ($element['#type'] == "radio") {
            $attributes['class'][] = 'radio';
            $is_radio = TRUE;
        } elseif ($element['#type'] == "checkbox") {
            $attributes['class'][] = 'checkbox';
            $is_checkbox = TRUE;
        } else {
            $attributes['class'][] = 'form-group';
        }
    }
    $description = FALSE;
    $tooltip = FALSE;
    // Convert some descriptions to tooltips.
    // @see bootstrap_tooltip_descriptions setting in _bootstrap_settings_form()
    // Mukurtu patch -- use tooltips for (almost) *all* form field descriptions:
    // 1. Do not limit to only descriptions under 200 chars
    // 2. For text area fields, the description is not yet available in $element, so load it from the field instance and use that.
    // 3. We are still respecting the markup condition (description === strip_tags($description)) because jquery-ui tooltips can't show markup
    // 4. Override the default placement of these tooltips from bootstrap's default "auto-left" to "bottom", because auto-left was failing to right (since there is no space at left), but right was very squeezed on smaller screens
    if (!empty($element['#description'])) {
        $description = $element['#description'];
    } elseif ($element['#type'] == 'textarea') {
        $textfield = field_info_instance($element['#entity_type'], $element['#field_name'], $element['#bundle']);
        $description = $textfield['description'];
    }
    if ($description) {
        if (theme_get_setting('bootstrap_tooltip_enabled') && theme_get_setting('bootstrap_tooltip_descriptions') && $description === strip_tags($description)) {
            $tooltip = TRUE;
            $attributes['data-toggle'] = 'tooltip';
            $attributes['data-placement'] = 'bottom';
            $attributes['title'] = $description;
        }
    }
    $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
    // If #title is not set, we don't display any label or required marker.
    if (!isset($element['#title'])) {
        $element['#title_display'] = 'none';
    }
    $prefix = '';
    $suffix = '';
    if (isset($element['#field_prefix']) || isset($element['#field_suffix'])) {
        // Determine if "#input_group" was specified.
        if (!empty($element['#input_group'])) {
            $prefix .= '<div class="input-group">';
            $prefix .= isset($element['#field_prefix']) ? '<span class="input-group-addon">' . $element['#field_prefix'] . '</span>' : '';
            $suffix .= isset($element['#field_suffix']) ? '<span class="input-group-addon">' . $element['#field_suffix'] . '</span>' : '';
            $suffix .= '</div>';
        } else {
            $prefix .= isset($element['#field_prefix']) ? $element['#field_prefix'] : '';
            $suffix .= isset($element['#field_suffix']) ? $element['#field_suffix'] : '';
        }
    }
    switch ($element['#title_display']) {
        case 'before':
        case 'invisible':
            $output .= ' ' . theme('form_element_label', $variables);
            $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
            break;
        case 'after':
            if ($is_radio || $is_checkbox) {
                $output .= ' ' . $prefix . $element['#children'] . $suffix;
            } else {
                $variables['#children'] = ' ' . $prefix . $element['#children'] . $suffix;
            }
            $output .= ' ' . theme('form_element_label', $variables) . "\n";
            break;
        case 'none':
        case 'attribute':
            // Output no label and no required marker, only the children.
            $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
            break;
    }
    if ($description && !$tooltip) {
        $output .= '<p class="help-block">' . $element['#description'] . "</p>\n";
    }
    $output .= "</div>\n";
    return $output;
}
/** Theme form element **/
function analytics_portal_form_element($variables)
{
    $element =& $variables['element'];
    // This function is invoked as theme wrapper, but the rendered form element
    // may not necessarily have been processed by form_builder().
    $element += array('#title_display' => 'before');
    // Add element #id for #type 'item'.
    if (isset($element['#markup']) && !empty($element['#id'])) {
        $attributes['id'] = $element['#id'];
    }
    // Add element's #type and #name as class to aid with JS/CSS selectors.
    $attributes['class'] = array('form-item');
    if (!empty($element['#type'])) {
        $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
    }
    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';
    }
    if (isset($element['#parents']) && form_get_error($element)) {
        $attributes['class'][] = 'has-error';
    }
    if ($element['#type'] != 'radio') {
        $attributes['class'][] = 'input-group';
    }
    $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
    // If #title is not set, we don't display any label or required marker.
    if (!isset($element['#title'])) {
        $element['#title_display'] = 'none';
    }
    $prefix = isset($element['#field_prefix']) ? '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' : '';
    $suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>' : '';
    switch ($element['#title_display']) {
        case 'before':
        case 'invisible':
            $output .= ' ' . theme('form_element_label', $variables);
            $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
            break;
        case 'after':
            $output .= ' ' . $prefix . $element['#children'] . $suffix;
            $output .= ' ' . theme('form_element_label', $variables) . "\n";
            break;
        case 'none':
        case 'attribute':
            // Output no label and no required marker, only the children.
            $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
            break;
    }
    // remove description we'll use placeholder.
    if (!empty($element['#description'])) {
        //$output .= '<div class="description">' . $element['#description'] . "</div>\n";
    }
    $output .= "</div>\n";
    return $output;
}