Example #1
3
/**
 * Preprocess input.
 */
function bootstrap_preprocess_input(&$variables)
{
    $element =& $variables['element'];
    $attributes = new Attribute($variables['attributes']);
    // Set the element's attributes.
    \Drupal\Core\Render\Element::setAttributes($element, array('id', 'name', 'value', 'type'));
    // Handle button inputs.
    if (_bootstrap_is_button($element)) {
        $variables['attributes']['class'][] = 'btn';
        _bootstrap_colorize_button($variables);
        _bootstrap_iconize_button($element);
        // Add button size, if necessary.
        if ($size = bootstrap_setting('button_size')) {
            $variables['attributes']['class'][] = $size;
        }
        // Add in the button type class.
        $variables['attributes']['class'][] = 'form-' . $element['#type'];
        $variables['label'] = $element['#value'];
    }
    _bootstrap_prerender_input($variables);
    // Autocomplete fields.
    if (!empty($element['#autocomplete_route_name']) && Drupal::PathValidator($element['#autocomplete_route_name'])) {
        $variables['autocomplete'] = TRUE;
        // Attributes for hidden input field.
        $autocomplete_attributes = new Attribute();
        $autocomplete_attributes['type'] = 'hidden';
        $autocomplete_attributes['id'] = $element['#attributes']['id'] . '-autocomplete';
        $autocomplete_attributes['value'] = Drupal::Url($element['#autocomplete_route_name'], $element['#autocomplete_route_parameters']);
        $autocomplete_attributes['disabled'] = 'disabled';
        $autocomplete_attributes['class'] = 'autocomplete';
        // Uses icon for autocomplete "throbber".
        $icon = _bootstrap_icon('refresh');
        // Fallback to using core's throbber.
        if (empty($icon)) {
            $icon = array('#type' => 'container', '#attributes' => array('class' => array('ajax-progress', 'ajax-progress-throbber', 'invisible')), 'throbber' => array('#type' => 'html_tag', '#tag' => 'div', '#attributes' => array('class' => array('throbber'))));
        }
        $variables['autocomplete_icon'] = $icon;
        $variables['autocomplete_attributes'] = $autocomplete_attributes;
    }
    // Search fields.
    if ($element['#type'] == 'search') {
        $attributes['placeholder'] = t('Search');
        $attributes['data-original-title'] = t('Enter the terms you wish to search for.');
    }
    // Additional Twig variables.
    $variables['icon'] = $element['#icon'];
    $variables['element'] = $element;
}
Example #2
0
/**
 * Pre-processes variables for the "region" theme hook.
 *
 * See template for list of available variables.
 *
 * @see region.tpl.php
 *
 * @ingroup theme_preprocess
 */
function bootstrap_preprocess_region(&$variables)
{
    $region = $variables['elements']['#region'];
    $variables['region'] = $region;
    $variables['content'] = $variables['elements']['#children'];
    $theme = \Drupal::theme()->getActiveTheme()->getName();
    // Content region.
    if ($region === 'content') {
        // @todo is this actually used properly?
        $variables['theme_hook_suggestions'][] = 'region__no_wrapper';
    } elseif ($region === 'help' && !empty($variables['content'])) {
        $content = $variables['content'];
        $variables['content'] = array('icon' => array('#markup' => _bootstrap_icon('question-sign')), 'content' => array('#markup' => $content));
        $variables['attributes']['class'][] = 'alert';
        $variables['attributes']['class'][] = 'alert-info';
        $variables['attributes']['class'][] = 'messages';
        $variables['attributes']['class'][] = 'info';
    }
    // Support for "well" classes in regions.
    static $wells;
    if (!isset($wells)) {
        foreach (system_region_list($theme) as $name => $title) {
            $wells[$name] = bootstrap_setting('region_well-' . $name);
        }
    }
    if (!empty($wells[$region])) {
        $variables['attributes']['class'][] = $wells[$region];
    }
}
Example #3
0
/**
 * Implements hook_preprocess_image_srcset().
 */
function bootstrap_preprocess_image_srcset(&$variables)
{
    // Add image shape, if necessary.
    if ($shape = bootstrap_setting('image_shape')) {
        $variables['attributes']['class'][] = $shape;
    }
}
Example #4
0
/**
 * Implements hook_preprocess_region().
 */
function bootstrap_preprocess_region(&$variables)
{
    global $theme;
    $region = $variables['region'];
    $classes =& $variables['classes_array'];
    // Content region.
    if ($region === 'content') {
        // @todo is this actually used properly?
        $variables['theme_hook_suggestions'][] = 'region__no_wrapper';
    } elseif ($region === 'help' && !empty($variables['content'])) {
        $variables['content'] = _bootstrap_icon('question-sign') . $variables['content'];
        $classes[] = 'alert';
        $classes[] = 'alert-info';
        $classes[] = 'messages';
        $classes[] = 'info';
    }
    // Support for "well" classes in regions.
    static $wells;
    if (!isset($wells)) {
        foreach (system_region_list($theme) as $name => $title) {
            $wells[$name] = bootstrap_setting('region_well-' . $name);
        }
    }
    if (!empty($wells[$region])) {
        $classes[] = $wells[$region];
    }
}
Example #5
0
/**
 * Pre-processes variables for the "picture" theme hook.
 *
 * See theme function for list of available variables.
 *
 * @see theme_picture()
 *
 * @ingroup theme_preprocess
 */
function bootstrap_preprocess_picture(&$variables)
{
    // Add responsiveness, if necessary.
    if ($shape = bootstrap_setting('image_responsive')) {
        $variables['attributes']['class'][] = 'img-responsive';
    }
}
Example #6
0
/**
 * Pre-processes variables for the "html" theme hook.
 *
 * See template for list of available variables.
 *
 * @see html.tpl.php
 *
 * @ingroup theme_preprocess
 */
function bootstrap_preprocess_html(&$variables)
{
    // Backport from Drupal 8 RDFa/HTML5 implementation.
    // @see https://www.drupal.org/node/1077566
    // @see https://www.drupal.org/node/1164926
    // HTML element attributes.
    $variables['html_attributes_array'] = array('lang' => $variables['language']->language, 'dir' => $variables['language']->dir);
    // Override existing RDF namespaces to use RDFa 1.1 namespace prefix bindings.
    if (function_exists('rdf_get_namespaces')) {
        $rdf = array('prefix' => array());
        foreach (rdf_get_namespaces() as $prefix => $uri) {
            $rdf['prefix'][] = $prefix . ': ' . $uri;
        }
        if (!$rdf['prefix']) {
            $rdf = array();
        }
        $variables['rdf_namespaces'] = drupal_attributes($rdf);
    }
    // BODY element attributes.
    $variables['body_attributes_array'] = array('class' => &$variables['classes_array']);
    $variables['body_attributes_array'] += $variables['attributes_array'];
    // Navbar position.
    switch (bootstrap_setting('navbar_position')) {
        case 'fixed-top':
            $variables['body_attributes_array']['class'][] = 'navbar-is-fixed-top';
            break;
        case 'fixed-bottom':
            $variables['body_attributes_array']['class'][] = 'navbar-is-fixed-bottom';
            break;
        case 'static-top':
            $variables['body_attributes_array']['class'][] = 'navbar-is-static-top';
            break;
    }
}
/**
 * Returns HTML for a link to the more extensive filter tips.
 *
 * @return string
 *   The constructed HTML.
 *
 * @see theme_filter_tips_more_info()
 *
 * @ingroup theme_functions
 */
function bootstrap_filter_tips_more_info()
{
    $attributes = array('target' => '_blank', 'title' => t('Opens in new window'));
    if (bootstrap_setting('tooltip_enabled')) {
        $attributes['data-toggle'] = 'tooltip';
    }
    return l(_bootstrap_icon('question-sign') . t('More information about text formats'), 'filter/tips', array('html' => TRUE, 'attributes' => $attributes));
}
Example #8
0
/**
 * Overrides theme_breadcrumb().
 *
 * Print breadcrumbs as an ordered list.
 */
function bootstrap_breadcrumb($variables)
{
    $output = '';
    $breadcrumb = $variables['breadcrumb'];
    // Determine if we are to display the breadcrumb.
    $bootstrap_breadcrumb = bootstrap_setting('breadcrumb');
    if (($bootstrap_breadcrumb == 1 || $bootstrap_breadcrumb == 2 && arg(0) == 'admin') && !empty($breadcrumb)) {
        $output = theme('item_list', array('attributes' => array('class' => array('breadcrumb')), 'items' => $breadcrumb, 'type' => 'ol'));
    }
    return $output;
}
Example #9
0
/**
 * Pre-processes variables for the "image" theme hook.
 *
 * See theme function for list of available variables.
 *
 * @see theme_image()
 *
 * @ingroup theme_preprocess
 */
function bootstrap_preprocess_image(&$variables)
{
    // Add image shape, if necessary.
    if ($shape = bootstrap_setting('image_shape')) {
        _bootstrap_add_class($shape, $variables);
    }
    // Add responsiveness, if necessary.
    if (bootstrap_setting('image_responsive')) {
        _bootstrap_add_class('img-responsive', $variables);
    }
}
Example #10
0
/**
 * Pre-processes variables for the "page" theme hook.
 *
 * See template for list of available variables.
 *
 * @see page.tpl.php
 *
 * @ingroup theme_preprocess
 */
function walk_preprocess_page(&$vars)
{
    // Add information about the number of sidebars.
    if (!empty($vars['page']['sidebar_first']) && !empty($vars['page']['sidebar_second'])) {
        $vars['content_column_class'] = ' class="col-sm-6"';
    } elseif (!empty($vars['page']['sidebar_first']) || !empty($vars['page']['sidebar_second'])) {
        $vars['content_column_class'] = ' class="col-sm-9"';
    } else {
        $vars['content_column_class'] = ' class="col-sm-12"';
    }
    if (bootstrap_setting('fluid_container') == 1) {
        $vars['container_class'] = 'container-fluid';
    } else {
        $vars['container_class'] = 'container';
    }
    // Primary nav.
    $vars['primary_nav'] = FALSE;
    if ($vars['main_menu']) {
        // Build links.
        $vars['primary_nav'] = menu_tree(variable_get('menu_main_links_source', 'main-menu'));
        // Provide default theme wrapper function.
        $vars['primary_nav']['#theme_wrappers'] = array('menu_tree__primary');
    }
    // Secondary nav.
    $vars['secondary_nav'] = FALSE;
    if ($vars['secondary_menu']) {
        // Build links.
        $vars['secondary_nav'] = menu_tree(variable_get('menu_secondary_links_source', 'user-menu'));
        // Provide default theme wrapper function.
        $vars['secondary_nav']['#theme_wrappers'] = array('menu_tree__secondary');
    }
    $vars['navbar_classes_array'] = array('navbar');
    if (bootstrap_setting('navbar_position') !== '') {
        $vars['navbar_classes_array'][] = 'navbar-' . bootstrap_setting('navbar_position');
    } elseif (bootstrap_setting('fluid_container') == 1) {
        $vars['navbar_classes_array'][] = 'container-fluid';
    } else {
        $vars['navbar_classes_array'][] = 'container';
    }
    if (bootstrap_setting('navbar_inverse')) {
        $vars['navbar_classes_array'][] = 'navbar-inverse';
    } else {
        $vars['navbar_classes_array'][] = 'navbar-default';
    }
    if (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'walk') {
        drupal_set_title('Hosting a Walk');
    }
    if (isset($vars['node']) && $vars['node']->nid == 12) {
        //dpm($vars);
        hide($vars['page']['content']['system_main']['nodes']);
    }
}
Example #11
0
/**
 * Pre-processes variables for the "html" theme hook.
 *
 * See template for list of available variables.
 *
 * @see html.tpl.php
 *
 * @ingroup theme_preprocess
 */
function bootstrap_preprocess_html(&$variables)
{
    switch (bootstrap_setting('navbar_position')) {
        case 'fixed-top':
            $variables['attributes']['class'][] = 'navbar-is-fixed-top';
            break;
        case 'fixed-bottom':
            $variables['attributes']['class'][] = 'navbar-is-fixed-bottom';
            break;
        case 'static-top':
            $variables['attributes']['class'][] = 'navbar-is-static-top';
            break;
    }
}
Example #12
0
/**
 * Returns HTML for a breadcrumb trail.
 *
 * @param array $variables
 *   An associative array containing:
 *   - breadcrumb: An array containing the breadcrumb links.
 *
 * @return string
 *   The constructed HTML.
 *
 * @see theme_breadcrumb()
 *
 * @ingroup theme_functions
 */
function bootstrap_breadcrumb($variables)
{
    // Use the Path Breadcrumbs theme function if it should be used instead.
    if (_bootstrap_use_path_breadcrumbs()) {
        return path_breadcrumbs_breadcrumb($variables);
    }
    $output = '';
    $breadcrumb = $variables['breadcrumb'];
    // Determine if we are to display the breadcrumb.
    $bootstrap_breadcrumb = bootstrap_setting('breadcrumb');
    if (($bootstrap_breadcrumb == 1 || $bootstrap_breadcrumb == 2 && arg(0) == 'admin') && !empty($breadcrumb)) {
        $output = theme('item_list', array('attributes' => array('class' => array('breadcrumb')), 'items' => $breadcrumb, 'type' => 'ol'));
    }
    return $output;
}
Example #13
0
/**
 * Implements hook_preprocess_breadcrumb().
 */
function bootstrap_preprocess_breadcrumb(&$variables)
{
    $breadcrumb =& $variables['breadcrumb'];
    // Optionally get rid of the homepage link.
    $show_breadcrumb_home = bootstrap_setting('breadcrumb_home');
    if (!$show_breadcrumb_home) {
        array_shift($breadcrumb);
    }
    if (bootstrap_setting('breadcrumb_title') && !empty($breadcrumb)) {
        $item = menu_get_item();
        $page_title = !empty($item['tab_parent']) ? check_plain($item['title']) : drupal_get_title();
        if (!empty($page_title)) {
            $breadcrumb[] = array('data' => $page_title, 'class' => array('active'));
        }
    }
}
Example #14
0
/**
 * Pre-processes variables for the "breadcrumb" theme hook.
 *
 * See theme function for list of available variables.
 *
 * @see bootstrap_breadcrumb()
 * @see theme_breadcrumb()
 *
 * @ingroup theme_preprocess
 */
function bootstrap_preprocess_breadcrumb(&$variables)
{
    $breadcrumb =& $variables['breadcrumb'];
    // Optionally get rid of the homepage link.
    $show_breadcrumb_home = bootstrap_setting('breadcrumb_home');
    if (!$show_breadcrumb_home) {
        array_shift($breadcrumb);
    }
    if (bootstrap_setting('breadcrumb_title') && !empty($breadcrumb)) {
        $request = \Drupal::request();
        $route_match = \Drupal::routeMatch();
        $page_title = \Drupal::service('title_resolver')->getTitle($request, $route_match->getRouteObject());
        if (!empty($page_title)) {
            $breadcrumb[] = array('text' => $page_title, 'attributes' => new Attribute(array('class' => array('active'))));
        }
    }
}
Example #15
0
/**
 * Pre-processes variables for the "page" theme hook.
 *
 * See template for list of available variables.
 *
 * @see page.tpl.php
 *
 * @ingroup theme_preprocess
 */
function angole_preprocess_page(&$variables)
{
    // Add information about the number of sidebars.
    if (!empty($variables['page']['sidebar_first']) && !empty($variables['page']['sidebar_second'])) {
        $variables['content_column_class'] = ' class="col-lg-6"';
    } elseif (!empty($variables['page']['sidebar_first']) || !empty($variables['page']['sidebar_second'])) {
        $variables['content_column_class'] = ' class="col-lg-9"';
    } else {
        $variables['content_column_class'] = ' class="col-lg-12"';
    }
    if (bootstrap_setting('fluid_container') == 1) {
        $variables['container_class'] = 'container-fluid';
    } else {
        $variables['container_class'] = 'container';
    }
    // Primary nav.
    $variables['primary_nav'] = FALSE;
    if ($variables['main_menu']) {
        // Build links.
        $variables['primary_nav'] = menu_tree(variable_get('menu_main_links_source', 'main-menu'));
        // Provide default theme wrapper function.
        $variables['primary_nav']['#theme_wrappers'] = array('menu_tree__primary');
    }
    // Secondary nav.
    $variables['secondary_nav'] = FALSE;
    if ($variables['secondary_menu']) {
        // Build links.
        $variables['secondary_nav'] = menu_tree(variable_get('menu_secondary_links_source', 'user-menu'));
        // Provide default theme wrapper function.
        $variables['secondary_nav']['#theme_wrappers'] = array('menu_tree__secondary');
    }
    $variables['navbar_classes_array'] = array('navbar');
    if (bootstrap_setting('navbar_position') !== '') {
        $variables['navbar_classes_array'][] = 'navbar-' . bootstrap_setting('navbar_position');
    } elseif (bootstrap_setting('fluid_container') == 1) {
        $variables['navbar_classes_array'][] = 'container-fluid';
    } else {
        $variables['navbar_classes_array'][] = 'container';
    }
    if (bootstrap_setting('navbar_inverse')) {
        $variables['navbar_classes_array'][] = 'navbar-inverse';
    } else {
        $variables['navbar_classes_array'][] = 'navbar-default';
    }
}
/**
 * Implements hook_preprocess_button().
 */
function bootstrap_preprocess_button(&$vars)
{
    $element =& $vars['element'];
    // Set the element's attributes.
    element_set_attributes($element, array('id', 'name', 'value', 'type'));
    // Add the base Bootstrap button class.
    $element['#attributes']['class'][] = 'btn';
    // Add button size, if necessary.
    if ($size = bootstrap_setting('button_size')) {
        $element['#attributes']['class'][] = $size;
    }
    // Colorize button.
    _bootstrap_colorize_button($element);
    // Add in the button type class.
    $element['#attributes']['class'][] = 'form-' . $element['#button_type'];
    // Ensure that all classes are unique, no need for duplicates.
    $element['#attributes']['class'] = array_unique($element['#attributes']['class']);
}
Example #17
0
/**
 * Pre-processes variables for the "page" theme hook.
 *
 * See template for list of available variables.
 *
 * @see page.tpl.php
 *
 * @ingroup theme_preprocess
 */
function bootstrap_preprocess_page(&$variables)
{
    // Add information about the number of sidebars.
    $variables['content_column_attributes'] = new Attribute();
    $variables['content_column_attributes']['class'] = array();
    if (!empty($variables['page']['sidebar_first']) && !empty($variables['page']['sidebar_second'])) {
        $variables['content_column_attributes']['class'][] = 'col-sm-6';
    } elseif (!empty($variables['page']['sidebar_first']) || !empty($variables['page']['sidebar_second'])) {
        $variables['content_column_attributes']['class'][] = 'col-sm-9';
    } else {
        $variables['content_column_attributes']['class'][] = 'col-sm-12';
    }
    $variables['navbar_attributes'] = new Attribute();
    $variables['navbar_attributes']['class'] = array('navbar');
    if (bootstrap_setting('navbar_position') !== '') {
        $variables['navbar_attributes']['class'][] = 'navbar-' . bootstrap_setting('navbar_position');
    } else {
        $variables['navbar_attributes']['class'][] = 'container';
    }
    if (bootstrap_setting('navbar_inverse')) {
        $variables['navbar_attributes']['class'][] = 'navbar-inverse';
    } else {
        $variables['navbar_attributes']['class'][] = 'navbar-default';
    }
    // Primary nav.
    $menu_tree = \Drupal::menuTree();
    // Render the top-level administration menu links.
    $parameters = new MenuTreeParameters();
    $tree = $menu_tree->load('main', $parameters);
    $manipulators = array(array('callable' => 'menu.default_tree_manipulators:checkAccess'), array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'));
    $tree = $menu_tree->transform($tree, $manipulators);
    $variables['primary_nav'] = $menu_tree->build($tree);
    $variables['primary_nav']['#attributes']['class'][] = 'navbar-nav';
    // Primary nav.
    $menu_tree = \Drupal::menuTree();
    // Render the top-level administration menu links.
    $parameters = new MenuTreeParameters();
    $tree = $menu_tree->load('account', $parameters);
    $manipulators = array(array('callable' => 'menu.default_tree_manipulators:checkAccess'), array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'));
    $tree = $menu_tree->transform($tree, $manipulators);
    $variables['secondary_nav'] = $menu_tree->build($tree);
    $variables['secondary_nav']['#attributes']['class'][] = 'navbar-nav';
    $variables['secondary_nav']['#attributes']['class'][] = 'secondary';
}
Example #18
0
/**
 * Pre-processes variables for the "button" theme hook.
 *
 * See theme function for list of available variables.
 *
 * @see bootstrap_button()
 * @see theme_button()
 *
 * @ingroup theme_preprocess
 */
function bootstrap_preprocess_button(&$vars)
{
    $element =& $vars['element'];
    // Drupal buttons should be of type 'submit'.
    // @see https://www.drupal.org/node/2540452
    $element['#attributes']['type'] = 'submit';
    // Set the element's other attributes.
    element_set_attributes($element, array('id', 'name', 'value'));
    // Add the base Bootstrap button class.
    $element['#attributes']['class'][] = 'btn';
    // Add button size, if necessary.
    if ($size = bootstrap_setting('button_size')) {
        $element['#attributes']['class'][] = $size;
    }
    // Colorize button.
    _bootstrap_colorize_button($element);
    // Add in the button type class.
    $element['#attributes']['class'][] = 'form-' . $element['#button_type'];
    // Ensure that all classes are unique, no need for duplicates.
    $element['#attributes']['class'] = array_unique($element['#attributes']['class']);
}
/**
 * Returns HTML for help text based on file upload validators.
 *
 * @param array $variables
 *   An associative array containing:
 *   - description: The normal description for this field, specified by the
 *     user.
 *   - upload_validators: An array of upload validators as used in
 *     $element['#upload_validators'].
 *
 * @return string
 *   The constructed HTML.
 *
 * @see theme_file_upload_help()
 *
 * @ingroup theme_functions
 */
function bootstrap_file_upload_help($variables)
{
    // If popover's are disabled, just theme this normally.
    if (!bootstrap_setting('popover_enabled')) {
        return theme_file_upload_help($variables);
    }
    $build = array();
    if (!empty($variables['description'])) {
        $build['description'] = array('#markup' => $variables['description'] . '<br>');
    }
    $descriptions = array();
    $upload_validators = $variables['upload_validators'];
    if (isset($upload_validators['file_validate_size'])) {
        $descriptions[] = t('Files must be less than !size.', array('!size' => '<strong>' . format_size($upload_validators['file_validate_size'][0]) . '</strong>'));
    }
    if (isset($upload_validators['file_validate_extensions'])) {
        $descriptions[] = t('Allowed file types: !extensions.', array('!extensions' => '<strong>' . check_plain($upload_validators['file_validate_extensions'][0]) . '</strong>'));
    }
    if (isset($upload_validators['file_validate_image_resolution'])) {
        $max = $upload_validators['file_validate_image_resolution'][0];
        $min = $upload_validators['file_validate_image_resolution'][1];
        if ($min && $max && $min == $max) {
            $descriptions[] = t('Images must be exactly !size pixels.', array('!size' => '<strong>' . $max . '</strong>'));
        } elseif ($min && $max) {
            $descriptions[] = t('Images must be between !min and !max pixels.', array('!min' => '<strong>' . $min . '</strong>', '!max' => '<strong>' . $max . '</strong>'));
        } elseif ($min) {
            $descriptions[] = t('Images must be larger than !min pixels.', array('!min' => '<strong>' . $min . '</strong>'));
        } elseif ($max) {
            $descriptions[] = t('Images must be smaller than !max pixels.', array('!max' => '<strong>' . $max . '</strong>'));
        }
    }
    if ($descriptions) {
        $id = drupal_html_id('upload-instructions');
        $build['instructions'] = array('#theme' => 'link__file_upload_requirements', '#text' => _bootstrap_icon('question-sign') . ' ' . t('More information'), '#path' => '#', '#options' => array('attributes' => array('data-toggle' => 'popover', 'data-target' => "#{$id}", 'data-html' => TRUE, 'data-placement' => 'bottom', 'data-title' => t('File requirements')), 'html' => TRUE, 'external' => TRUE));
        $build['requirements'] = array('#theme_wrappers' => array('container__file_upload_requirements'), '#attributes' => array('id' => $id, 'class' => array('element-invisible', 'help-block')));
        $build['requirements']['validators'] = array('#theme' => 'item_list__file_upload_requirements', '#items' => $descriptions);
    }
    return drupal_render($build);
}
Example #20
0
/**
 * Helper function for adding the necessary classes to a table.
 *
 * @param array $classes
 *   The array of classes, passed by reference.
 * @param array $variables
 *   The variables of the theme hook, passed by reference.
 */
function _bootstrap_table_add_classes(&$classes, &$variables)
{
    $context = $variables['context'];
    // Generic table class for all tables.
    $classes[] = 'table';
    // Bordered table.
    if (!empty($context['bordered']) || bootstrap_setting('table_bordered')) {
        $classes[] = 'table-bordered';
    }
    // Condensed table.
    if (!empty($context['condensed']) || bootstrap_setting('table_condensed')) {
        $classes[] = 'table-condensed';
    }
    // Hover rows.
    if (!empty($context['hover']) || bootstrap_setting('table_hover')) {
        $classes[] = 'table-hover';
    }
    // Striped rows.
    if (!empty($context['striped']) || bootstrap_setting('table_striped')) {
        $classes[] = 'table-striped';
    }
    $variables['responsive'] = !empty($context['responsive']) ? $context['responsive'] : bootstrap_setting('table_responsive');
}
Example #21
0
/**
 * Returns HTML for a query pager.
 *
 * Menu callbacks that display paged query results should call theme('pager') to
 * retrieve a pager control so that users can view other results. Format a list
 * of nearby pages with additional query results.
 *
 * @param array $variables
 *   An associative array containing:
 *   - tags: An array of labels for the controls in the pager.
 *   - element: An optional integer to distinguish between multiple pagers on
 *     one page.
 *   - parameters: An associative array of query string parameters to append to
 *     the pager links.
 *   - quantity: The number of pages in the list.
 *
 * @return string
 *   The constructed HTML.
 *
 * @see theme_pager()
 *
 * @ingroup theme_functions
 */
function bootstrap_pager($variables)
{
    $output = "";
    $items = array();
    $tags = $variables['tags'];
    $element = $variables['element'];
    $parameters = $variables['parameters'];
    $quantity = $variables['quantity'];
    global $pager_page_array, $pager_total;
    // Calculate various markers within this pager piece:
    // Middle is used to "center" pages around the current page.
    $pager_middle = ceil($quantity / 2);
    // Current is the page we are currently paged to.
    $pager_current = $pager_page_array[$element] + 1;
    // First is the first page listed by this pager piece (re quantity).
    $pager_first = $pager_current - $pager_middle + 1;
    // Last is the last page listed by this pager piece (re quantity).
    $pager_last = $pager_current + $quantity - $pager_middle;
    // Max is the maximum page number.
    $pager_max = $pager_total[$element];
    // Prepare for generation loop.
    $i = $pager_first;
    if ($pager_last > $pager_max) {
        // Adjust "center" if at end of query.
        $i = $i + ($pager_max - $pager_last);
        $pager_last = $pager_max;
    }
    if ($i <= 0) {
        // Adjust "center" if at start of query.
        $pager_last = $pager_last + (1 - $i);
        $i = 1;
    }
    // End of generation loop preparation.
    $li_first = theme('pager_first', array('text' => isset($tags[0]) ? $tags[0] : t('first'), 'element' => $element, 'parameters' => $parameters));
    $li_previous = theme('pager_previous', array('text' => isset($tags[1]) ? $tags[1] : t('previous'), 'element' => $element, 'interval' => 1, 'parameters' => $parameters));
    $li_next = theme('pager_next', array('text' => isset($tags[3]) ? $tags[3] : t('next'), 'element' => $element, 'interval' => 1, 'parameters' => $parameters));
    $li_last = theme('pager_last', array('text' => isset($tags[4]) ? $tags[4] : t('last'), 'element' => $element, 'parameters' => $parameters));
    if ($pager_total[$element] > 1) {
        // Only show "first" link if set on components' theme setting
        if ($li_first && bootstrap_setting('pager_first_and_last')) {
            $items[] = array('class' => array('pager-first'), 'data' => $li_first);
        }
        if ($li_previous) {
            $items[] = array('class' => array('prev'), 'data' => $li_previous);
        }
        // When there is more than one page, create the pager list.
        if ($i != $pager_max) {
            if ($i > 1) {
                $items[] = array('class' => array('pager-ellipsis', 'disabled'), 'data' => '<span>…</span>');
            }
            // Now generate the actual pager piece.
            for (; $i <= $pager_last && $i <= $pager_max; $i++) {
                if ($i < $pager_current) {
                    $items[] = array('data' => theme('pager_previous', array('text' => $i, 'element' => $element, 'interval' => $pager_current - $i, 'parameters' => $parameters)));
                }
                if ($i == $pager_current) {
                    $items[] = array('class' => array('active'), 'data' => "<span>{$i}</span>");
                }
                if ($i > $pager_current) {
                    $items[] = array('data' => theme('pager_next', array('text' => $i, 'element' => $element, 'interval' => $i - $pager_current, 'parameters' => $parameters)));
                }
            }
            if ($i < $pager_max) {
                $items[] = array('class' => array('pager-ellipsis', 'disabled'), 'data' => '<span>…</span>');
            }
        }
        // End generation.
        if ($li_next) {
            $items[] = array('class' => array('next'), 'data' => $li_next);
        }
        // // Only show "last" link if set on components' theme setting
        if ($li_last && bootstrap_setting('pager_first_and_last')) {
            $items[] = array('class' => array('pager-last'), 'data' => $li_last);
        }
        $build = array('#theme_wrappers' => array('container__pager'), '#attributes' => array('class' => array('text-center')), 'pager' => array('#theme' => 'item_list', '#items' => $items, '#attributes' => array('class' => array('pagination'))));
        return drupal_render($build);
    }
    return $output;
}
/**
 * Implements hook_form_FORM_ID_alter().
 */
function bootstrap_form_system_theme_settings_alter(&$form, $form_state, $form_id = NULL)
{
    // Do not add Bootstrap specific settings to non-bootstrap based themes,
    // including a work-around for a core bug affecting admin themes.
    // @see https://drupal.org/node/943212
    $theme = !empty($form_state['build_info']['args'][0]) ? $form_state['build_info']['args'][0] : FALSE;
    if (isset($form_id) || $theme === FALSE || !in_array('bootstrap', _bootstrap_get_base_themes($theme, TRUE))) {
        return;
    }
    // Display a warning if jquery_update isn't enabled.
    if ((!module_exists('jquery_update') || !version_compare(variable_get('jquery_update_jquery_version', '1.10'), '1.9', '>=')) && !bootstrap_setting('toggle_jquery_error', $theme)) {
        drupal_set_message(t('jQuery Update is not enabled, Bootstrap requires a minimum jQuery version of 1.9 or higher. Please enable the <a href="!jquery_update_project_url">jQuery Update</a> module @jquery_update_version or higher. If you are seeing this, then you must <a href="!jquery_update_configure">manually configuration</a> this setting or optionally <a href="!bootstrap_suppress_jquery_error">suppress this message</a> instead.', array('@jquery_update_version' => '7.x-2.5', '!jquery_update_project_url' => 'https://www.drupal.org/project/jquery_update', '!jquery_update_configure' => url('admin/config/development/jquery_update'), '!bootstrap_suppress_jquery_error' => url('admin/appearance/settings/' . $theme, array('fragment' => 'edit-bootstrap-toggle-jquery-error')))), 'error', FALSE);
    }
    // Create vertical tabs for all Bootstrap related settings.
    $form['bootstrap'] = array('#type' => 'vertical_tabs', '#attached' => array('js' => array(drupal_get_path('theme', 'bootstrap') . '/js/bootstrap.admin.js')), '#prefix' => '<h2><small>' . t('Bootstrap Settings') . '</small></h2>', '#weight' => -10);
    // General.
    $form['general'] = array('#type' => 'fieldset', '#title' => t('General'), '#group' => 'bootstrap');
    //Container
    $form['general']['container'] = array('#type' => 'fieldset', '#title' => t('Container'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['general']['container']['bootstrap_fluid_container'] = array('#type' => 'checkbox', '#title' => t('Fluid container'), '#default_value' => bootstrap_setting('fluid_container', $theme), '#description' => t('Use <code>.container-fluid</code> class. See <a href="http://getbootstrap.com/css/#grid-example-fluid">Fluid container</a>'));
    // Buttons.
    $form['general']['buttons'] = array('#type' => 'fieldset', '#title' => t('Buttons'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['general']['buttons']['bootstrap_button_size'] = array('#type' => 'select', '#title' => t('Default button size'), '#default_value' => bootstrap_setting('button_size', $theme), '#empty_option' => t('Normal'), '#options' => array('btn-xs' => t('Extra Small'), 'btn-sm' => t('Small'), 'btn-lg' => t('Large')));
    $form['general']['buttons']['bootstrap_button_colorize'] = array('#type' => 'checkbox', '#title' => t('Colorize Buttons'), '#default_value' => bootstrap_setting('button_colorize', $theme), '#description' => t('Adds classes to buttons based on their text value. See: <a href="!bootstrap_url" target="_blank">Buttons</a> and <a href="!api_url" target="_blank">hook_bootstrap_colorize_text_alter()</a>', array('!bootstrap_url' => 'http://getbootstrap.com/css/#buttons', '!api_url' => 'http://drupalcode.org/project/bootstrap.git/blob/refs/heads/7.x-3.x:/bootstrap.api.php#l13')));
    $form['general']['buttons']['bootstrap_button_iconize'] = array('#type' => 'checkbox', '#title' => t('Iconize Buttons'), '#default_value' => bootstrap_setting('button_iconize', $theme), '#description' => t('Adds icons to buttons based on the text value. See: <a href="!api_url" target="_blank">hook_bootstrap_iconize_text_alter()</a>', array('!api_url' => 'http://drupalcode.org/project/bootstrap.git/blob/refs/heads/7.x-3.x:/bootstrap.api.php#l37')));
    // Forms.
    $form['general']['forms'] = array('#type' => 'fieldset', '#title' => t('Forms'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['general']['forms']['bootstrap_forms_required_has_error'] = array('#type' => 'checkbox', '#title' => t('Make required elements display as an error'), '#default_value' => bootstrap_setting('forms_required_has_error', $theme), '#description' => t('If an element in a form is required, enabling this will always display the element with a <code>.has-error</code> class. This turns the element red and helps in usability for determining which form elements are required to submit the form.  This feature compliments the "JavaScript > Forms > Automatically remove error classes when values have been entered" feature.'));
    // Images.
    $form['general']['images'] = array('#type' => 'fieldset', '#title' => t('Images'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['general']['images']['bootstrap_image_shape'] = array('#type' => 'select', '#title' => t('Default image shape'), '#description' => t('Add classes to an <code>&lt;img&gt;</code> element to easily style images in any project. Note: Internet Explorer 8 lacks support for rounded corners. See: <a href="!bootstrap_url" target="_blank">Image Shapes</a>', array('!bootstrap_url' => 'http://getbootstrap.com/css/#images-shapes')), '#default_value' => bootstrap_setting('image_shape', $theme), '#empty_option' => t('None'), '#options' => array('img-rounded' => t('Rounded'), 'img-circle' => t('Circle'), 'img-thumbnail' => t('Thumbnail')));
    $form['general']['images']['bootstrap_image_responsive'] = array('#type' => 'checkbox', '#title' => t('Responsive Images'), '#default_value' => bootstrap_setting('image_responsive', $theme), '#description' => t('Images in Bootstrap 3 can be made responsive-friendly via the addition of the <code>.img-responsive</code> class. This applies <code>max-width: 100%;</code> and <code>height: auto;</code> to the image so that it scales nicely to the parent element.'));
    // Tables.
    $form['general']['tables'] = array('#type' => 'fieldset', '#title' => t('Tables'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['general']['tables']['bootstrap_table_bordered'] = array('#type' => 'checkbox', '#title' => t('Bordered table'), '#default_value' => bootstrap_setting('table_bordered', $theme), '#description' => t('Add borders on all sides of the table and cells.'));
    $form['general']['tables']['bootstrap_table_condensed'] = array('#type' => 'checkbox', '#title' => t('Condensed table'), '#default_value' => bootstrap_setting('table_condensed', $theme), '#description' => t('Make tables more compact by cutting cell padding in half.'));
    $form['general']['tables']['bootstrap_table_hover'] = array('#type' => 'checkbox', '#title' => t('Hover rows'), '#default_value' => bootstrap_setting('table_hover', $theme), '#description' => t('Enable a hover state on table rows.'));
    $form['general']['tables']['bootstrap_table_striped'] = array('#type' => 'checkbox', '#title' => t('Striped rows'), '#default_value' => bootstrap_setting('table_striped', $theme), '#description' => t('Add zebra-striping to any table row within the <code>&lt;tbody&gt;</code>. <strong>Note:</strong> Striped tables are styled via the <code>:nth-child</code> CSS selector, which is not available in Internet Explorer 8.'));
    $form['general']['tables']['bootstrap_table_responsive'] = array('#type' => 'checkbox', '#title' => t('Responsive tables'), '#default_value' => bootstrap_setting('table_responsive', $theme), '#description' => t('Makes tables responsive by wrapping them in <code>.table-responsive</code> to make them scroll horizontally up to small devices (under 768px). When viewing on anything larger than 768px wide, you will not see any difference in these tables.'));
    // Components.
    $form['components'] = array('#type' => 'fieldset', '#title' => t('Components'), '#group' => 'bootstrap');
    // Breadcrumbs.
    $form['components']['breadcrumbs'] = array('#type' => 'fieldset', '#title' => t('Breadcrumbs'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['components']['breadcrumbs']['bootstrap_breadcrumb'] = array('#type' => 'select', '#title' => t('Breadcrumb visibility'), '#default_value' => bootstrap_setting('breadcrumb', $theme), '#options' => array(0 => t('Hidden'), 1 => t('Visible'), 2 => t('Only in admin areas')));
    $form['components']['breadcrumbs']['bootstrap_breadcrumb_home'] = array('#type' => 'checkbox', '#title' => t('Show "Home" breadcrumb link'), '#default_value' => bootstrap_setting('breadcrumb_home', $theme), '#description' => t('If your site has a module dedicated to handling breadcrumbs already, ensure this setting is enabled.'), '#states' => array('invisible' => array(':input[name="bootstrap_breadcrumb"]' => array('value' => 0))));
    $form['components']['breadcrumbs']['bootstrap_breadcrumb_title'] = array('#type' => 'checkbox', '#title' => t('Show current page title at end'), '#default_value' => bootstrap_setting('breadcrumb_title', $theme), '#description' => t('If your site has a module dedicated to handling breadcrumbs already, ensure this setting is disabled.'), '#states' => array('invisible' => array(':input[name="bootstrap_breadcrumb"]' => array('value' => 0))));
    // Navbar.
    $form['components']['navbar'] = array('#type' => 'fieldset', '#title' => t('Navbar'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['components']['navbar']['bootstrap_navbar_position'] = array('#type' => 'select', '#title' => t('Navbar Position'), '#description' => t('Select your Navbar position.'), '#default_value' => bootstrap_setting('navbar_position', $theme), '#options' => array('static-top' => t('Static Top'), 'fixed-top' => t('Fixed Top'), 'fixed-bottom' => t('Fixed Bottom')), '#empty_option' => t('Normal'));
    $form['components']['navbar']['bootstrap_navbar_inverse'] = array('#type' => 'checkbox', '#title' => t('Inverse navbar style'), '#description' => t('Select if you want the inverse navbar style.'), '#default_value' => bootstrap_setting('navbar_inverse', $theme));
    // Region wells.
    $wells = array('' => t('None'), 'well' => t('.well (normal)'), 'well well-sm' => t('.well-sm (small)'), 'well well-lg' => t('.well-lg (large)'));
    $form['components']['region_wells'] = array('#type' => 'fieldset', '#title' => t('Region wells'), '#description' => t('Enable the <code>.well</code>, <code>.well-sm</code> or <code>.well-lg</code> classes for specified regions. See: documentation on !wells.', array('!wells' => l(t('Bootstrap Wells'), 'http://getbootstrap.com/components/#wells'))), '#collapsible' => TRUE, '#collapsed' => TRUE);
    // Get defined regions.
    $regions = system_region_list($theme);
    foreach ($regions as $name => $title) {
        $form['components']['region_wells']['bootstrap_region_well-' . $name] = array('#title' => $title, '#type' => 'select', '#attributes' => array('class' => array('input-sm')), '#options' => $wells, '#default_value' => bootstrap_setting('region_well-' . $name, $theme));
    }
    // JavaScript settings.
    $form['javascript'] = array('#type' => 'fieldset', '#title' => t('JavaScript'), '#group' => 'bootstrap');
    // Anchors.
    $form['javascript']['anchors'] = array('#type' => 'fieldset', '#title' => t('Anchors'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['javascript']['anchors']['bootstrap_anchors_fix'] = array('#type' => 'checkbox', '#title' => t('Fix anchor positions'), '#default_value' => bootstrap_setting('anchors_fix', $theme), '#description' => t('Ensures anchors are correctly positioned only when there is margin or padding detected on the BODY element. This is useful when fixed navbar or administration menus are used.'));
    $form['javascript']['anchors']['bootstrap_anchors_smooth_scrolling'] = array('#type' => 'checkbox', '#title' => t('Enable smooth scrolling'), '#default_value' => bootstrap_setting('anchors_smooth_scrolling', $theme), '#description' => t('Animates page by scrolling to an anchor link target smoothly when clicked.'), '#states' => array('invisible' => array(':input[name="bootstrap_anchors_fix"]' => array('checked' => FALSE))));
    // Forms.
    $form['javascript']['forms'] = array('#type' => 'fieldset', '#title' => t('Forms'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['javascript']['forms']['bootstrap_forms_has_error_value_toggle'] = array('#type' => 'checkbox', '#title' => t('Automatically remove error classes when values have been entered'), '#default_value' => bootstrap_setting('forms_has_error_value_toggle', $theme), '#description' => t('If an element has a <code>.has-error</code> class attached to it, enabling this will automatically remove that class when a value is entered. This feature compliments the "General > Forms > Make required elements display as an error" feature.'));
    $form['javascript']['forms']['bootstrap_tooltip_descriptions'] = array('#type' => 'checkbox', '#title' => t('Use Tooltips for simple form descriptions'), '#description' => t('Form items that contain simple descriptions (no HTML, no title attribute and are less than the specified length below) will be converted into tooltips. This helps reduce the sometimes unnecessary noise of form item descriptions. Descriptions that contain longer text or HTML as actionable descriptions (user needs to click) will not be converted. This ensures it is always visible so its usability remains intact.'), '#default_value' => bootstrap_setting('tooltip_descriptions', $theme), '#states' => array('visible' => array(':input[name="bootstrap_tooltip_enabled"]' => array('checked' => TRUE))));
    // Popovers.
    $form['javascript']['popovers'] = array('#type' => 'fieldset', '#title' => t('Popovers'), '#description' => t('Add small overlays of content, like those on the iPad, to any element for housing secondary information.'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['javascript']['popovers']['bootstrap_popover_enabled'] = array('#type' => 'checkbox', '#title' => t('Enable popovers.'), '#description' => t('Elements that have the !code attribute set will automatically initialize the popover upon page load. !warning', array('!code' => '<code>data-toggle="popover"</code>', '!warning' => '<strong class="error text-error">WARNING: This feature can sometimes impact performance. Disable if pages appear to "hang" after initial load.</strong>')), '#default_value' => bootstrap_setting('popover_enabled', $theme));
    $form['javascript']['popovers']['options'] = array('#type' => 'fieldset', '#title' => t('Options'), '#description' => t('These are global options. Each popover can independently override desired settings by appending the option name to !data. Example: !data-animation.', array('!data' => '<code>data-</code>', '!data-animation' => '<code>data-animation="false"</code>')), '#collapsible' => TRUE, '#collapsed' => TRUE, '#states' => array('visible' => array(':input[name="bootstrap_popover_enabled"]' => array('checked' => TRUE))));
    $form['javascript']['popovers']['options']['bootstrap_popover_animation'] = array('#type' => 'checkbox', '#title' => t('animate'), '#description' => t('Apply a CSS fade transition to the popover.'), '#default_value' => bootstrap_setting('popover_animation', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_html'] = array('#type' => 'checkbox', '#title' => t('HTML'), '#description' => t("Insert HTML into the popover. If false, jQuery's text method will be used to insert content into the DOM. Use text if you're worried about XSS attacks."), '#default_value' => bootstrap_setting('popover_html', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_placement'] = array('#type' => 'select', '#title' => t('placement'), '#description' => t('Where to position the popover. When "auto" is specified, it will dynamically reorient the popover. For example, if placement is "auto left", the popover will display to the left when possible, otherwise it will display right.'), '#default_value' => bootstrap_setting('popover_placement', $theme), '#options' => drupal_map_assoc(array('top', 'bottom', 'left', 'right', 'auto', 'auto top', 'auto bottom', 'auto left', 'auto right')));
    $form['javascript']['popovers']['options']['bootstrap_popover_selector'] = array('#type' => 'textfield', '#title' => t('selector'), '#description' => t('If a selector is provided, tooltip objects will be delegated to the specified targets. In practice, this is used to enable dynamic HTML content to have popovers added. See !this and !example.', array('!this' => l(t('this'), 'https://github.com/twbs/bootstrap/issues/4215'), '!example' => l(t('an informative example'), 'http://jsfiddle.net/fScua/'))), '#default_value' => bootstrap_setting('popover_selector', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_trigger'] = array('#type' => 'checkboxes', '#title' => t('trigger'), '#description' => t('How a popover is triggered.'), '#default_value' => bootstrap_setting('popover_trigger', $theme), '#options' => drupal_map_assoc(array('click', 'hover', 'focus', 'manual')));
    $form['javascript']['popovers']['options']['bootstrap_popover_trigger_autoclose'] = array('#type' => 'checkbox', '#title' => t('Auto-close on document click'), '#description' => t('Will automatically close the current popover if a click occurs anywhere else other than the popover element.'), '#default_value' => bootstrap_setting('popover_trigger_autoclose', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_title'] = array('#type' => 'textfield', '#title' => t('title'), '#description' => t("Default title value if \"title\" attribute isn't present."), '#default_value' => bootstrap_setting('popover_title', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_content'] = array('#type' => 'textfield', '#title' => t('content'), '#description' => t('Default content value if "data-content" or "data-target" attributes are not present.'), '#default_value' => bootstrap_setting('popover_content', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_delay'] = array('#type' => 'textfield', '#title' => t('delay'), '#description' => t('The amount of time to delay showing and hiding the popover (in milliseconds). Does not apply to manual trigger type.'), '#default_value' => bootstrap_setting('popover_delay', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_container'] = array('#type' => 'textfield', '#title' => t('container'), '#description' => t('Appends the popover to a specific element. Example: "body". This option is particularly useful in that it allows you to position the popover in the flow of the document near the triggering element - which will prevent the popover from floating away from the triggering element during a window resize.'), '#default_value' => bootstrap_setting('popover_container', $theme));
    // Tooltips.
    $form['javascript']['tooltips'] = array('#type' => 'fieldset', '#title' => t('Tooltips'), '#description' => t("Inspired by the excellent jQuery.tipsy plugin written by Jason Frame; Tooltips are an updated version, which don't rely on images, use CSS3 for animations, and data-attributes for local title storage. See !link for more documentation.", array('!link' => l(t('Bootstrap tooltips'), 'http://getbootstrap.com/javascript/#tooltips'))), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['javascript']['tooltips']['bootstrap_tooltip_enabled'] = array('#type' => 'checkbox', '#title' => t('Enable tooltips'), '#description' => t('Elements that have the !code attribute set will automatically initialize the tooltip upon page load. !warning', array('!code' => '<code>data-toggle="tooltip"</code>', '!warning' => '<strong class="error text-error">WARNING: This feature can sometimes impact performance. Disable if pages appear to "hang" after initial load.</strong>')), '#default_value' => bootstrap_setting('tooltip_enabled', $theme));
    $form['javascript']['tooltips']['bootstrap_tooltip_descriptions_length'] = array('#type' => 'textfield', '#title' => t('Simple form description length'), '#description' => t('The character length limit used to determine when a description makes a sense to be used as a tooltip.'), '#default_value' => bootstrap_setting('tooltip_descriptions_length', $theme), '#states' => array('visible' => array(':input[name="bootstrap_tooltip_enabled"]' => array('checked' => TRUE), ':input[name="bootstrap_tooltip_descriptions"]' => array('checked' => TRUE))));
    $form['javascript']['tooltips']['options'] = array('#type' => 'fieldset', '#title' => t('Options'), '#description' => t('These are global options. Each tooltip can independently override desired settings by appending the option name to !data. Example: !data-animation.', array('!data' => '<code>data-</code>', '!data-animation' => '<code>data-animation="false"</code>')), '#collapsible' => TRUE, '#collapsed' => TRUE, '#states' => array('visible' => array(':input[name="bootstrap_tooltip_enabled"]' => array('checked' => TRUE))));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_animation'] = array('#type' => 'checkbox', '#title' => t('animate'), '#description' => t('Apply a CSS fade transition to the tooltip.'), '#default_value' => bootstrap_setting('tooltip_animation', $theme));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_html'] = array('#type' => 'checkbox', '#title' => t('HTML'), '#description' => t("Insert HTML into the tooltip. If false, jQuery's text method will be used to insert content into the DOM. Use text if you're worried about XSS attacks."), '#default_value' => bootstrap_setting('tooltip_html', $theme));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_placement'] = array('#type' => 'select', '#title' => t('placement'), '#description' => t('Where to position the tooltip. When "auto" is specified, it will dynamically reorient the tooltip. For example, if placement is "auto left", the tooltip will display to the left when possible, otherwise it will display right.'), '#default_value' => bootstrap_setting('tooltip_placement', $theme), '#options' => drupal_map_assoc(array('top', 'bottom', 'left', 'right', 'auto', 'auto top', 'auto bottom', 'auto left', 'auto right')));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_selector'] = array('#type' => 'textfield', '#title' => t('selector'), '#description' => t('If a selector is provided, tooltip objects will be delegated to the specified targets.'), '#default_value' => bootstrap_setting('tooltip_selector', $theme));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_trigger'] = array('#type' => 'checkboxes', '#title' => t('trigger'), '#description' => t('How a tooltip is triggered.'), '#default_value' => bootstrap_setting('tooltip_trigger', $theme), '#options' => drupal_map_assoc(array('click', 'hover', 'focus', 'manual')));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_delay'] = array('#type' => 'textfield', '#title' => t('delay'), '#description' => t('The amount of time to delay showing and hiding the tooltip (in milliseconds). Does not apply to manual trigger type.'), '#default_value' => bootstrap_setting('tooltip_delay', $theme));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_container'] = array('#type' => 'textfield', '#title' => t('container'), '#description' => t('Appends the tooltip to a specific element. Example: "body"'), '#default_value' => bootstrap_setting('tooltip_container', $theme));
    // Advanced settings.
    $form['advanced'] = array('#type' => 'fieldset', '#title' => t('Advanced'), '#group' => 'bootstrap');
    // jQuery Update error suppression.
    $form['advanced']['bootstrap_toggle_jquery_error'] = array('#type' => 'checkbox', '#title' => t('Suppress jQuery version error message'), '#default_value' => bootstrap_setting('toggle_jquery_error', $theme), '#description' => t('Enable this if the version of jQuery has been upgraded to 1.9+ using a method other than the <a href="!jquery_update" target="_blank">jQuery Update</a> module.', array('!jquery_update' => 'https://drupal.org/project/jquery_update')));
    // BootstrapCDN.
    bootstrap_cdn_provider_settings_form($form, $form_state, $theme);
}
Example #23
0
/**
 * Implements hook_form_FORM_ID_alter().
 */
function d4s_bootstrap_form_system_theme_settings_alter(&$form, $form_state, $form_id = NULL)
{
    // Do not add Bootstrap specific settings to non-bootstrap based themes,
    // including a work-around for a core bug affecting admin themes.
    // @see https://drupal.org/node/943212
    $theme = !empty($form_state['build_info']['args'][0]) ? $form_state['build_info']['args'][0] : FALSE;
    if (isset($form_id) || $theme === FALSE || !in_array('bootstrap', _bootstrap_get_base_themes($theme, TRUE))) {
        return;
    }
    // Display a warning if jQuery Update isn't enabled or using a lower version.
    if (!bootstrap_setting('toggle_jquery_error', $theme) || !module_exists('jquery_update')) {
        // Get theme specific jQuery version.
        $jquery_version = theme_get_setting('jquery_update_jquery_version', $theme);
        // Get site wide jQuery version if theme specific one is not set.
        if (!$jquery_version) {
            $jquery_version = variable_get('jquery_update_jquery_version', '1.10');
        }
        // Ensure the jQuery version is >= 1.9.
        if (!$jquery_version || !version_compare($jquery_version, '1.9', '>=')) {
            $message = t('jQuery Update is not enabled, Bootstrap requires a minimum jQuery version of 1.9 or higher. Please enable the <a href="!jquery_update_project_url">jQuery Update</a> module. If you are seeing this message, then you must <a href="!jquery_update_configure">manually configuration</a> this setting or optionally <a href="!bootstrap_suppress_jquery_error">suppress this message</a> instead.', array('!jquery_update_project_url' => check_plain('https://www.drupal.org/project/jquery_update'), '!jquery_update_configure' => check_plain(url('admin/config/development/jquery_update')), '!bootstrap_suppress_jquery_error' => check_plain(url('admin/appearance/settings/' . $theme, array('fragment' => 'edit-bootstrap-toggle-jquery-error')))));
            drupal_set_message($message, 'error', FALSE);
        }
    }
    // Create vertical tabs for all Bootstrap related settings.
    $form['bootstrap'] = array('#type' => 'vertical_tabs', '#attached' => array('js' => array(drupal_get_path('theme', 'd4s_bootstrap') . '/js/bootstrap.admin.js')), '#prefix' => '<h2><small>' . t('Drupal4School Accessibility Bootstrap Settings') . '</small></h2>', '#weight' => -10);
    // General.
    $form['general'] = array('#type' => 'fieldset', '#title' => t('General'), '#group' => 'bootstrap');
    //Container
    $form['general']['container'] = array('#type' => 'fieldset', '#title' => t('Container'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['general']['container']['bootstrap_fluid_container'] = array('#type' => 'checkbox', '#title' => t('Fluid container'), '#default_value' => bootstrap_setting('fluid_container', $theme), '#description' => t('Use <code>.container-fluid</code> class. See <a href="!url" target="_blank">Fluid container</a>', array('!url' => 'http://getbootstrap.com/css/#grid-example-fluid')));
    // Buttons.
    $form['general']['buttons'] = array('#type' => 'fieldset', '#title' => t('Buttons'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['general']['buttons']['bootstrap_button_size'] = array('#type' => 'select', '#title' => t('Default button size'), '#default_value' => bootstrap_setting('button_size', $theme), '#empty_option' => t('Normal'), '#options' => array('btn-xs' => t('Extra Small'), 'btn-sm' => t('Small'), 'btn-lg' => t('Large')));
    $form['general']['buttons']['bootstrap_button_colorize'] = array('#type' => 'checkbox', '#title' => t('Colorize Buttons'), '#default_value' => bootstrap_setting('button_colorize', $theme), '#description' => t('Adds classes to buttons based on their text value. See: <a href="!bootstrap_url" target="_blank">Buttons</a> and <a href="!api_url" target="_blank">hook_bootstrap_colorize_text_alter()</a>', array('!bootstrap_url' => 'http://getbootstrap.com/css/#buttons-options', '!api_url' => 'http://drupal-bootstrap.org/apis/hook_bootstrap_colorize_text_alter')));
    $form['general']['buttons']['bootstrap_button_iconize'] = array('#type' => 'checkbox', '#title' => t('Iconize Buttons'), '#default_value' => bootstrap_setting('button_iconize', $theme), '#description' => t('Adds icons to buttons based on the text value. See: <a href="!api_url" target="_blank">hook_bootstrap_iconize_text_alter()</a>', array('!api_url' => 'http://drupal-bootstrap.org/apis/hook_bootstrap_iconize_text_alter')));
    // Forms.
    $form['general']['forms'] = array('#type' => 'fieldset', '#title' => t('Forms'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['general']['forms']['bootstrap_forms_required_has_error'] = array('#type' => 'checkbox', '#title' => t('Make required elements display as an error'), '#default_value' => bootstrap_setting('forms_required_has_error', $theme), '#description' => t('If an element in a form is required, enabling this will always display the element with a <code>.has-error</code> class. This turns the element red and helps in usability for determining which form elements are required to submit the form.  This feature compliments the "JavaScript > Forms > Automatically remove error classes when values have been entered" feature.'));
    $form['general']['forms']['bootstrap_forms_smart_descriptions'] = array('#type' => 'checkbox', '#title' => t('Smart form descriptions (via Tooltips)'), '#description' => t('Convert descriptions into tooltips (must be enabled) automatically based on certain criteria. This helps reduce the, sometimes unnecessary, amount of noise on a page full of form elements.'), '#default_value' => bootstrap_setting('forms_smart_descriptions', $theme));
    $form['general']['forms']['bootstrap_forms_smart_descriptions_limit'] = array('#type' => 'textfield', '#title' => t('"Smart form descriptions" maximum character limit'), '#description' => t('Prevents descriptions from becoming tooltips by checking the character length of the description (HTML is not counted towards this limit). To disable this filtering criteria, leave an empty value.'), '#default_value' => bootstrap_setting('forms_smart_descriptions_limit', $theme), '#states' => array('visible' => array(':input[name="bootstrap_forms_smart_descriptions"]' => array('checked' => TRUE))));
    $form['general']['forms']['bootstrap_forms_smart_descriptions_allowed_tags'] = array('#type' => 'textfield', '#title' => t('"Smart form descriptions" allowed (HTML) tags'), '#description' => t('Prevents descriptions from becoming tooltips by checking for HTML not in the list above (i.e. links). Separate by commas. To disable this filtering criteria, leave an empty value.'), '#default_value' => bootstrap_setting('forms_smart_descriptions_allowed_tags', $theme), '#states' => array('visible' => array(':input[name="bootstrap_forms_smart_descriptions"]' => array('checked' => TRUE))));
    // Images.
    $form['general']['images'] = array('#type' => 'fieldset', '#title' => t('Images'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['general']['images']['bootstrap_image_shape'] = array('#type' => 'select', '#title' => t('Default image shape'), '#description' => t('Add classes to an <code>&lt;img&gt;</code> element to easily style images in any project. Note: Internet Explorer 8 lacks support for rounded corners. See: <a href="!bootstrap_url" target="_blank">Image Shapes</a>', array('!bootstrap_url' => 'http://getbootstrap.com/css/#images-shapes')), '#default_value' => bootstrap_setting('image_shape', $theme), '#empty_option' => t('None'), '#options' => array('img-rounded' => t('Rounded'), 'img-circle' => t('Circle'), 'img-thumbnail' => t('Thumbnail')));
    $form['general']['images']['bootstrap_image_responsive'] = array('#type' => 'checkbox', '#title' => t('Responsive Images'), '#default_value' => bootstrap_setting('image_responsive', $theme), '#description' => t('Images in Bootstrap 3 can be made responsive-friendly via the addition of the <code>.img-responsive</code> class. This applies <code>max-width: 100%;</code> and <code>height: auto;</code> to the image so that it scales nicely to the parent element.'));
    // Tables.
    $form['general']['tables'] = array('#type' => 'fieldset', '#title' => t('Tables'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['general']['tables']['bootstrap_table_bordered'] = array('#type' => 'checkbox', '#title' => t('Bordered table'), '#default_value' => bootstrap_setting('table_bordered', $theme), '#description' => t('Add borders on all sides of the table and cells.'));
    $form['general']['tables']['bootstrap_table_condensed'] = array('#type' => 'checkbox', '#title' => t('Condensed table'), '#default_value' => bootstrap_setting('table_condensed', $theme), '#description' => t('Make tables more compact by cutting cell padding in half.'));
    $form['general']['tables']['bootstrap_table_hover'] = array('#type' => 'checkbox', '#title' => t('Hover rows'), '#default_value' => bootstrap_setting('table_hover', $theme), '#description' => t('Enable a hover state on table rows.'));
    $form['general']['tables']['bootstrap_table_striped'] = array('#type' => 'checkbox', '#title' => t('Striped rows'), '#default_value' => bootstrap_setting('table_striped', $theme), '#description' => t('Add zebra-striping to any table row within the <code>&lt;tbody&gt;</code>. <strong>Note:</strong> Striped tables are styled via the <code>:nth-child</code> CSS selector, which is not available in Internet Explorer 8.'));
    $form['general']['tables']['bootstrap_table_responsive'] = array('#type' => 'checkbox', '#title' => t('Responsive tables'), '#default_value' => bootstrap_setting('table_responsive', $theme), '#description' => t('Makes tables responsive by wrapping them in <code>.table-responsive</code> to make them scroll horizontally up to small devices (under 768px). When viewing on anything larger than 768px wide, you will not see any difference in these tables.'));
    // Components.
    $form['components'] = array('#type' => 'fieldset', '#title' => t('Components'), '#group' => 'bootstrap');
    // Breadcrumbs.
    $form['components']['breadcrumbs'] = array('#type' => 'fieldset', '#title' => t('Breadcrumbs'));
    // Show message for Path Breadcrumbs module support.
    if (_bootstrap_use_path_breadcrumbs($theme)) {
        $form['components']['breadcrumbs']['#description'] = t('The <a href="!path_breadcrumbs" target="_blank">Path Breadcrumbs</a> module is being used to manage this site\'s breadcrumbs display and cannot be configured via theme settings. To configure this site\'s breadcrumbs display, enable the <a href="!enable">Path Breadcrumbs UI</a> sub-module and then visit <a href="!settings">Path Breadcrumbs Settings</a>.', array('!path_breadcrumbs' => 'https://www.drupal.org/project/path_breadcrumbs', '!enable' => url('admin/modules', array('fragment' => 'edit-modules-path-breadcrumbs')), '!settings' => url('admin/structure/path-breadcrumbs/settings')));
    } else {
        $form['components']['breadcrumbs']['#collapsible'] = TRUE;
        $form['components']['breadcrumbs']['#collapsed'] = TRUE;
        $form['components']['breadcrumbs']['bootstrap_breadcrumb'] = array('#type' => 'select', '#title' => t('Breadcrumb visibility'), '#default_value' => bootstrap_setting('breadcrumb', $theme), '#options' => array(0 => t('Hidden'), 1 => t('Visible'), 2 => t('Only in admin areas')));
        $form['components']['breadcrumbs']['bootstrap_breadcrumb_home'] = array('#type' => 'checkbox', '#title' => t('Show "Home" breadcrumb link'), '#default_value' => bootstrap_setting('breadcrumb_home', $theme), '#description' => t('If your site has a module dedicated to handling breadcrumbs already, ensure this setting is enabled.'), '#states' => array('invisible' => array(':input[name="bootstrap_breadcrumb"]' => array('value' => 0))));
        $form['components']['breadcrumbs']['bootstrap_breadcrumb_title'] = array('#type' => 'checkbox', '#title' => t('Show current page title at end'), '#default_value' => bootstrap_setting('breadcrumb_title', $theme), '#description' => t('If your site has a module dedicated to handling breadcrumbs already, ensure this setting is disabled.'), '#states' => array('invisible' => array(':input[name="bootstrap_breadcrumb"]' => array('value' => 0))));
    }
    // Navbar.
    $form['components']['navbar'] = array('#type' => 'fieldset', '#title' => t('Navbar'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['components']['navbar']['bootstrap_navbar_position'] = array('#type' => 'select', '#title' => t('Navbar Position'), '#description' => t('Select your Navbar position.'), '#default_value' => bootstrap_setting('navbar_position', $theme), '#options' => array('static-top' => t('Static Top'), 'fixed-top' => t('Fixed Top'), 'fixed-bottom' => t('Fixed Bottom')), '#empty_option' => t('Normal'));
    $form['components']['navbar']['bootstrap_navbar_inverse'] = array('#type' => 'checkbox', '#title' => t('Inverse navbar style'), '#description' => t('Select if you want the inverse navbar style.'), '#default_value' => bootstrap_setting('navbar_inverse', $theme));
    // Pager
    $form['components']['pager'] = array('#type' => 'fieldset', '#title' => t('Pagination'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['components']['pager']['bootstrap_pager_first_and_last'] = array('#type' => 'checkbox', '#title' => t('Show "First" and "Last" links in the pager'), '#description' => t('Allow user to choose whether to display "First" and "Last" links on pagers.'), '#default_value' => bootstrap_setting('pager_first_and_last', $theme));
    // Region wells.
    $wells = array('' => t('None'), 'well' => t('.well (normal)'), 'well well-sm' => t('.well-sm (small)'), 'well well-lg' => t('.well-lg (large)'));
    $form['components']['region_wells'] = array('#type' => 'fieldset', '#title' => t('Region wells'), '#description' => t('Enable the <code>.well</code>, <code>.well-sm</code> or <code>.well-lg</code> classes for specified regions. See: documentation on <a href="!wells" target="_blank">Bootstrap Wells</a>.', array('!wells' => 'http://getbootstrap.com/components/#wells')), '#collapsible' => TRUE, '#collapsed' => TRUE);
    // Get defined regions.
    $regions = system_region_list($theme);
    foreach ($regions as $name => $title) {
        $form['components']['region_wells']['bootstrap_region_well-' . $name] = array('#title' => $title, '#type' => 'select', '#attributes' => array('class' => array('input-sm')), '#options' => $wells, '#default_value' => bootstrap_setting('region_well-' . $name, $theme));
    }
    // JavaScript settings.
    $form['javascript'] = array('#type' => 'fieldset', '#title' => t('JavaScript'), '#group' => 'bootstrap');
    // Anchors.
    $form['javascript']['anchors'] = array('#type' => 'fieldset', '#title' => t('Anchors'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#description' => t('This plugin is not able to be configured from the UI as it is severely broken. In an effort to balance not break backwards compatibility and to prevent new users from running into unforeseen issues, you must manually opt-in/out inside your theme .info file. Please see the following issue for more details: <a href="!url" target="_blank">Replace custom JS with the bootstrap-anchor plugin</a>', array('!url' => 'https://www.drupal.org/node/2462645')));
    $form['javascript']['anchors']['bootstrap_anchors_fix'] = array('#type' => 'checkbox', '#title' => t('Fix anchor positions'), '#default_value' => bootstrap_setting('anchors_fix', $theme), '#description' => t('Ensures anchors are correctly positioned only when there is margin or padding detected on the BODY element. This is useful when fixed navbar or administration menus are used.'), '#disabled' => TRUE);
    $form['javascript']['anchors']['bootstrap_anchors_smooth_scrolling'] = array('#type' => 'checkbox', '#title' => t('Enable smooth scrolling'), '#default_value' => bootstrap_setting('anchors_smooth_scrolling', $theme), '#description' => t('Animates page by scrolling to an anchor link target smoothly when clicked.'), '#states' => array('invisible' => array(':input[name="bootstrap_anchors_fix"]' => array('checked' => FALSE))), '#disabled' => TRUE);
    // Forms.
    $form['javascript']['forms'] = array('#type' => 'fieldset', '#title' => t('Forms'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['javascript']['forms']['bootstrap_forms_has_error_value_toggle'] = array('#type' => 'checkbox', '#title' => t('Automatically remove error classes when values have been entered'), '#default_value' => bootstrap_setting('forms_has_error_value_toggle', $theme), '#description' => t('If an element has a <code>.has-error</code> class attached to it, enabling this will automatically remove that class when a value is entered. This feature compliments the "General > Forms > Make required elements display as an error" feature.'));
    // Popovers.
    $form['javascript']['popovers'] = array('#type' => 'fieldset', '#title' => t('Popovers'), '#description' => t('Add small overlays of content, like those on the iPad, to any element for housing secondary information.'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['javascript']['popovers']['bootstrap_popover_enabled'] = array('#type' => 'checkbox', '#title' => t('Enable popovers.'), '#description' => t('Elements that have the <code>data-toggle="popover"</code> attribute set will automatically initialize the popover upon page load. <strong class="error text-error">WARNING: This feature can sometimes impact performance. Disable if pages appear to "hang" after initial load.</strong>'), '#default_value' => bootstrap_setting('popover_enabled', $theme));
    $form['javascript']['popovers']['options'] = array('#type' => 'fieldset', '#title' => t('Options'), '#description' => t('These are global options. Each popover can independently override desired settings by appending the option name to <code>data-</code>. Example: <code>data-animation="false"</code>.'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#states' => array('visible' => array(':input[name="bootstrap_popover_enabled"]' => array('checked' => TRUE))));
    $form['javascript']['popovers']['options']['bootstrap_popover_animation'] = array('#type' => 'checkbox', '#title' => t('animate'), '#description' => t('Apply a CSS fade transition to the popover.'), '#default_value' => bootstrap_setting('popover_animation', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_html'] = array('#type' => 'checkbox', '#title' => t('HTML'), '#description' => t("Insert HTML into the popover. If false, jQuery's text method will be used to insert content into the DOM. Use text if you're worried about XSS attacks."), '#default_value' => bootstrap_setting('popover_html', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_placement'] = array('#type' => 'select', '#title' => t('placement'), '#description' => t('Where to position the popover. When "auto" is specified, it will dynamically reorient the popover. For example, if placement is "auto left", the popover will display to the left when possible, otherwise it will display right.'), '#default_value' => bootstrap_setting('popover_placement', $theme), '#options' => drupal_map_assoc(array('top', 'bottom', 'left', 'right', 'auto', 'auto top', 'auto bottom', 'auto left', 'auto right')));
    $form['javascript']['popovers']['options']['bootstrap_popover_selector'] = array('#type' => 'textfield', '#title' => t('selector'), '#description' => t('If a selector is provided, tooltip objects will be delegated to the specified targets. In practice, this is used to enable dynamic HTML content to have popovers added. See <a href="!this" target="_blank">this</a> and <a href="!example" target="_blank">an informative example</a>.', array('!this' => 'https://github.com/twbs/bootstrap/issues/4215', '!example' => 'http://jsfiddle.net/fScua/')), '#default_value' => bootstrap_setting('popover_selector', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_trigger'] = array('#type' => 'checkboxes', '#title' => t('trigger'), '#description' => t('How a popover is triggered.'), '#default_value' => bootstrap_setting('popover_trigger', $theme), '#options' => drupal_map_assoc(array('click', 'hover', 'focus', 'manual')));
    $form['javascript']['popovers']['options']['bootstrap_popover_trigger_autoclose'] = array('#type' => 'checkbox', '#title' => t('Auto-close on document click'), '#description' => t('Will automatically close the current popover if a click occurs anywhere else other than the popover element.'), '#default_value' => bootstrap_setting('popover_trigger_autoclose', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_title'] = array('#type' => 'textfield', '#title' => t('title'), '#description' => t("Default title value if \"title\" attribute isn't present."), '#default_value' => bootstrap_setting('popover_title', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_content'] = array('#type' => 'textfield', '#title' => t('content'), '#description' => t('Default content value if "data-content" or "data-target" attributes are not present.'), '#default_value' => bootstrap_setting('popover_content', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_delay'] = array('#type' => 'textfield', '#title' => t('delay'), '#description' => t('The amount of time to delay showing and hiding the popover (in milliseconds). Does not apply to manual trigger type.'), '#default_value' => bootstrap_setting('popover_delay', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_container'] = array('#type' => 'textfield', '#title' => t('container'), '#description' => t('Appends the popover to a specific element. Example: "body". This option is particularly useful in that it allows you to position the popover in the flow of the document near the triggering element - which will prevent the popover from floating away from the triggering element during a window resize.'), '#default_value' => bootstrap_setting('popover_container', $theme));
    // Tooltips.
    $form['javascript']['tooltips'] = array('#type' => 'fieldset', '#title' => t('Tooltips'), '#description' => t('Inspired by the excellent jQuery.tipsy plugin written by Jason Frame; Tooltips are an updated version, which don\'t rely on images, use CSS3 for animations, and data-attributes for local title storage. See <a href="!url" target="_blank">Bootstrap tooltips</a> for more documentation.', array('!url' => 'http://getbootstrap.com/javascript/#tooltips')), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['javascript']['tooltips']['bootstrap_tooltip_enabled'] = array('#type' => 'checkbox', '#title' => t('Enable tooltips'), '#description' => t('Elements that have the <code>data-toggle="tooltip"</code> attribute set will automatically initialize the tooltip upon page load. <strong class="error text-error">WARNING: This feature can sometimes impact performance. Disable if pages appear to "hang" after initial load.</strong>'), '#default_value' => bootstrap_setting('tooltip_enabled', $theme));
    $form['javascript']['tooltips']['options'] = array('#type' => 'fieldset', '#title' => t('Options'), '#description' => t('These are global options. Each tooltip can independently override desired settings by appending the option name to <code>data-</code>. Example: <code>data-animation="false"</code>.'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#states' => array('visible' => array(':input[name="bootstrap_tooltip_enabled"]' => array('checked' => TRUE))));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_animation'] = array('#type' => 'checkbox', '#title' => t('animate'), '#description' => t('Apply a CSS fade transition to the tooltip.'), '#default_value' => bootstrap_setting('tooltip_animation', $theme));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_html'] = array('#type' => 'checkbox', '#title' => t('HTML'), '#description' => t("Insert HTML into the tooltip. If false, jQuery's text method will be used to insert content into the DOM. Use text if you're worried about XSS attacks."), '#default_value' => bootstrap_setting('tooltip_html', $theme));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_placement'] = array('#type' => 'select', '#title' => t('placement'), '#description' => t('Where to position the tooltip. When "auto" is specified, it will dynamically reorient the tooltip. For example, if placement is "auto left", the tooltip will display to the left when possible, otherwise it will display right.'), '#default_value' => bootstrap_setting('tooltip_placement', $theme), '#options' => drupal_map_assoc(array('top', 'bottom', 'left', 'right', 'auto', 'auto top', 'auto bottom', 'auto left', 'auto right')));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_selector'] = array('#type' => 'textfield', '#title' => t('selector'), '#description' => t('If a selector is provided, tooltip objects will be delegated to the specified targets.'), '#default_value' => bootstrap_setting('tooltip_selector', $theme));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_trigger'] = array('#type' => 'checkboxes', '#title' => t('trigger'), '#description' => t('How a tooltip is triggered.'), '#default_value' => bootstrap_setting('tooltip_trigger', $theme), '#options' => drupal_map_assoc(array('click', 'hover', 'focus', 'manual')));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_delay'] = array('#type' => 'textfield', '#title' => t('delay'), '#description' => t('The amount of time to delay showing and hiding the tooltip (in milliseconds). Does not apply to manual trigger type.'), '#default_value' => bootstrap_setting('tooltip_delay', $theme));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_container'] = array('#type' => 'textfield', '#title' => t('container'), '#description' => t('Appends the tooltip to a specific element. Example: "body"'), '#default_value' => bootstrap_setting('tooltip_container', $theme));
    // Advanced settings.
    $form['advanced'] = array('#type' => 'fieldset', '#title' => t('Advanced'), '#group' => 'bootstrap');
    // jQuery Update error suppression.
    $form['advanced']['bootstrap_toggle_jquery_error'] = array('#type' => 'checkbox', '#title' => t('Suppress jQuery version error message'), '#default_value' => bootstrap_setting('toggle_jquery_error', $theme), '#description' => t('Enable this if the version of jQuery has been upgraded to 1.9+ using a method other than the <a href="!jquery_update" target="_blank">jQuery Update</a> module.', array('!jquery_update' => 'https://drupal.org/project/jquery_update')));
    // BootstrapCDN.
    bootstrap_cdn_provider_settings_form($form, $form_state, $theme);
    // Accessibility Settings.
    $form['mtt_settings'] = array('#type' => 'fieldset', '#title' => t('Accessibility'), '#collapsible' => TRUE, '#collapsed' => FALSE, '#group' => 'bootstrap');
    $form['mtt_settings']['Accessibility'] = array('#type' => 'fieldset', '#title' => t('Accessibility Guide Brick'), '#collapsible' => TRUE, '#collapsed' => FALSE);
    $form['mtt_settings']['Accessibility']['access_brick'] = array('#type' => 'checkbox', '#title' => t('Show guide brick'), '#default_value' => theme_get_setting('access_brick', 'd4s_bootstrap'), '#description' => t('After enabled guide brick function, you still have to build their own instructions page (<em> Administer -> Content -> Add new content </em>), and then create a link for the page, placed prominently on the home page position (<em> Administer -> Structure -> Menu </em>)!'));
    $form['mtt_settings']['menu'] = array('#type' => 'fieldset', '#title' => t('Navigation Menu'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['mtt_settings']['menu']['main_navigation'] = array('#type' => 'textfield', '#title' => t('Accesskey for Navigation Menu'), '#default_value' => theme_get_setting('main_navigation', 'd4s_bootstrap'), '#description' => t('Now that we know has been used by browser as keyboard shortcuts, include: d, e, f. This block using access key Alt+n by default!'));
    $form['mtt_settings']['header_block'] = array('#type' => 'fieldset', '#title' => t('Header'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['mtt_settings']['header_block']['header'] = array('#type' => 'textfield', '#title' => t('Accesskey for Header Block'), '#default_value' => theme_get_setting('header', 'd4s_bootstrap'), '#description' => t('This block using access key Alt+h by default!'));
    $form['mtt_settings']['sidebar'] = array('#type' => 'fieldset', '#title' => t('Sidebar'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['mtt_settings']['sidebar']['sidebar_first'] = array('#type' => 'textfield', '#title' => t('Accesskey for First Sidebar'), '#default_value' => theme_get_setting('sidebar_first', 'd4s_bootstrap'), '#description' => t('This block using access key Alt+r by default!'));
    $form['mtt_settings']['sidebar']['sidebar_second'] = array('#type' => 'textfield', '#title' => t('Accesskey for Second Sidebar'), '#default_value' => theme_get_setting('sidebar_second', 'd4s_bootstrap'), '#description' => t('This block using access key Alt+s by default!'));
    $form['mtt_settings']['highlighted_block'] = array('#type' => 'fieldset', '#title' => t('Highlighted'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['mtt_settings']['highlighted_block']['highlighted'] = array('#type' => 'textfield', '#title' => t('Accesskey for Highlighted Block'), '#default_value' => theme_get_setting('highlighted', 'd4s_bootstrap'), '#description' => t('This block using access key Alt+i by default!'));
    $form['mtt_settings']['content'] = array('#type' => 'fieldset', '#title' => t('Content'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['mtt_settings']['content']['main_content'] = array('#type' => 'textfield', '#title' => t('Accesskey for Main Content'), '#default_value' => theme_get_setting('main_content', 'd4s_bootstrap'), '#description' => t('This block using access key Alt+c by default!'));
    $form['mtt_settings']['content']['help'] = array('#type' => 'textfield', '#title' => t('Accesskey for Help Content'), '#default_value' => theme_get_setting('help', 'd4s_bootstrap'), '#description' => t('This block using access key Alt+p by default!'));
    $form['mtt_settings']['footer_block'] = array('#type' => 'fieldset', '#title' => t('Footer'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['mtt_settings']['footer_block']['footer'] = array('#type' => 'textfield', '#title' => t('Accesskey for Footer block'), '#default_value' => theme_get_setting('footer', 'd4s_bootstrap'), '#description' => t('This block using access key Alt+o by default!'));
    /*	$form['adaptive_menu'] = array(
    		'#type' => 'fieldset',
    		'#title' => t('Adaptive Menu'),
    		'#collapsible' => TRUE,
    		'#collapsed' => TRUE,
    		'#description'   => t('Please select the menu to be displayed in the navigation region, this function will automatic switching to the specified menu based on user identity.'),
    		'#group' => 'bootstrap',
      );
      
    	$all_menus = menu_load_all();
    	foreach($all_menus as $menu_id => $menu) {
    		$menu_title = $menu['title'];
    		$all_menus[$menu_id] = $menu_title;
      }
      
    	$form['adaptive_menu']['anonymous_menu'] = array(
    		'#type' => 'select',
    		'#title' => t('Menu for Anonymous'),
    		'#multiple' => FALSE,
    		'#options' => $all_menus,
    		'#size' => 1,
    		'#default_value' => theme_get_setting('anonymous_menu','d4s_bootstrap'),
      );
      
    	$form['adaptive_menu']['teacher_menu'] = array(
    		'#type' => 'select',
    		'#title' => t('Menu for Teachers'),
    		'#multiple' => FALSE,
    		'#options' => $all_menus,
    		'#size' => 1,
    		'#default_value' => theme_get_setting('teacher_menu','d4s_bootstrap'),
      );
      
    	$form['adaptive_menu']['student_menu'] = array(
    		'#type' => 'select',
    		'#title' => t('Menu for Students'),
    		'#multiple' => FALSE,
    		'#options' => $all_menus,
    		'#size' => 1,
    		'#default_value' => theme_get_setting('student_menu','d4s_bootstrap'),
      );*/
    $form['credits'] = array('#type' => 'fieldset', '#title' => t('Credits'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#group' => 'bootstrap');
    $form['credits']['credits_display'] = array('#type' => 'checkbox', '#title' => t('Show credits'), '#description' => t('Use the checkbox to enable or disable credits.'), '#default_value' => theme_get_setting('credits_display', 'd4s_bootstrap'));
}
Example #24
0
/**
 * Implements hook_form_FORM_ID_alter().
 */
function bootstrap_form_system_theme_settings_alter(&$form, FormStateInterface $form_state, $form_id = NULL)
{
    // Do not add Bootstrap specific settings to non-bootstrap based themes,
    // including a work-around for a core bug affecting admin themes.
    // @see https://drupal.org/node/943212
    $args = $form_state->getBuildInfo()['args'];
    // Do not add Bootstrap specific settings to non-bootstrap based themes.
    $theme = !empty($args[0]) ? $args[0] : FALSE;
    if (isset($form_id) || $theme === FALSE || !in_array('bootstrap', _bootstrap_get_base_themes($theme, TRUE))) {
        return;
    }
    $form['bootstrap'] = array('#type' => 'vertical_tabs', '#attached' => array('library' => array('bootstrap/adminscript')), '#prefix' => '<h2><small>' . t('Bootstrap Settings') . '</small></h2>', '#weight' => -10);
    // General.
    $form['general'] = array('#type' => 'details', '#title' => t('General'), '#group' => 'bootstrap');
    // Container.
    $form['general']['container'] = array('#type' => 'fieldset', '#title' => t('Container'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['general']['container']['bootstrap_fluid_container'] = array('#type' => 'checkbox', '#title' => t('Fluid container'), '#default_value' => bootstrap_setting('fluid_container', $theme), '#description' => t('Use <code>.container-fluid</code> class. See <a href=":url">Fluid container</a>', array(':url' => 'http://getbootstrap.com/css/#grid-example-fluid')));
    // Buttons.
    $form['general']['buttons'] = array('#type' => 'details', '#title' => t('Buttons'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['general']['buttons']['bootstrap_button_size'] = array('#type' => 'select', '#title' => t('Default button size'), '#default_value' => bootstrap_setting('button_size', $theme), '#empty_option' => t('Normal'), '#options' => array('btn-xs' => t('Extra Small'), 'btn-sm' => t('Small'), 'btn-lg' => t('Large')));
    $form['general']['buttons']['bootstrap_button_colorize'] = array('#type' => 'checkbox', '#title' => t('Colorize Buttons'), '#default_value' => bootstrap_setting('button_colorize', $theme), '#description' => t('Adds classes to buttons based on their text value. See: <a href=":bootstrap_url" target="_blank">Buttons</a> and <a href=":api_url" target="_blank">hook_bootstrap_colorize_text_alter()</a>', array(':bootstrap_url' => 'http://getbootstrap.com/css/#buttons', ':api_url' => 'http://drupal-bootstrap.org/apis/hook_bootstrap_colorize_text_alter')));
    $form['general']['buttons']['bootstrap_button_iconize'] = array('#type' => 'checkbox', '#title' => t('Iconize Buttons'), '#default_value' => bootstrap_setting('button_iconize', $theme), '#description' => t('Adds icons to buttons based on the text value. See: <a href=":api_url" target="_blank">hook_bootstrap_iconize_text_alter()</a>', array(':api_url' => 'http://drupal-bootstrap.org/apis/hook_bootstrap_iconize_text_alter')));
    // Forms.
    $form['general']['forms'] = array('#type' => 'details', '#title' => t('Forms'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['general']['forms']['bootstrap_forms_required_has_error'] = array('#type' => 'checkbox', '#title' => t('Make required elements display as an error'), '#default_value' => bootstrap_setting('forms_required_has_error', $theme), '#description' => t('If an element in a form is required, enabling this will always display the element with a <code>.has-error</code> class. This turns the element red and helps in usability for determining which form elements are required to submit the form.  This feature compliments the "JavaScript > Forms > Automatically remove error classes when values have been entered" feature.'));
    $form['general']['forms']['bootstrap_forms_smart_descriptions'] = array('#type' => 'checkbox', '#title' => t('Smart form descriptions (via Tooltips)'), '#description' => t('Convert descriptions into tooltips (must be enabled) automatically based on certain criteria. This helps reduce the, sometimes unnecessary, amount of noise on a page full of form elements.'), '#default_value' => bootstrap_setting('forms_smart_descriptions', $theme));
    $form['general']['forms']['bootstrap_forms_smart_descriptions_limit'] = array('#type' => 'textfield', '#title' => t('"Smart form descriptions" maximum character limit'), '#description' => t('Prevents descriptions from becoming tooltips by checking the character length of the description (HTML is not counted towards this limit). To disable this filtering criteria, leave an empty value.'), '#default_value' => bootstrap_setting('forms_smart_descriptions_limit', $theme), '#states' => array('visible' => array(':input[name="bootstrap_forms_smart_descriptions"]' => array('checked' => TRUE))));
    $form['general']['forms']['bootstrap_forms_smart_descriptions_allowed_tags'] = array('#type' => 'textfield', '#title' => t('"Smart form descriptions" allowed (HTML) tags'), '#description' => t('Prevents descriptions from becoming tooltips by checking for HTML not in the list above (i.e. links). Separate by commas. To disable this filtering criteria, leave an empty value.'), '#default_value' => bootstrap_setting('forms_smart_descriptions_allowed_tags', $theme), '#states' => array('visible' => array(':input[name="bootstrap_forms_smart_descriptions"]' => array('checked' => TRUE))));
    // Images.
    $form['general']['images'] = array('#type' => 'details', '#title' => t('Images'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['general']['images']['bootstrap_image_shape'] = array('#type' => 'select', '#title' => t('Default image shape'), '#description' => t('Add classes to an <code>&lt;img&gt;</code> element to easily style images in any project. Note: Internet Explorer 8 lacks support for rounded corners. See: <a href=":bootstrap_url" target="_blank">Image Shapes</a>', array(':bootstrap_url' => 'http://getbootstrap.com/css/#images-shapes')), '#default_value' => bootstrap_setting('image_shape', $theme), '#empty_option' => t('None'), '#options' => array('img-rounded' => t('Rounded'), 'img-circle' => t('Circle'), 'img-thumbnail' => t('Thumbnail')));
    $form['general']['images']['bootstrap_image_responsive'] = array('#type' => 'checkbox', '#title' => t('Responsive Images'), '#default_value' => bootstrap_setting('image_responsive', $theme), '#description' => t('Images in Bootstrap 3 can be made responsive-friendly via the addition of the <code>.img-responsive</code> class. This applies <code>max-width: 100%;</code> and <code>height: auto;</code> to the image so that it scales nicely to the parent element.'));
    // Tables.
    $form['general']['tables'] = array('#type' => 'details', '#title' => t('Tables'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['general']['tables']['bootstrap_table_bordered'] = array('#type' => 'checkbox', '#title' => t('Bordered table'), '#default_value' => bootstrap_setting('table_bordered', $theme), '#description' => t('Add borders on all sides of the table and cells.'));
    $form['general']['tables']['bootstrap_table_condensed'] = array('#type' => 'checkbox', '#title' => t('Condensed table'), '#default_value' => bootstrap_setting('table_condensed', $theme), '#description' => t('Make tables more compact by cutting cell padding in half.'));
    $form['general']['tables']['bootstrap_table_hover'] = array('#type' => 'checkbox', '#title' => t('Hover rows'), '#default_value' => bootstrap_setting('table_hover', $theme), '#description' => t('Enable a hover state on table rows.'));
    $form['general']['tables']['bootstrap_table_striped'] = array('#type' => 'checkbox', '#title' => t('Striped rows'), '#default_value' => bootstrap_setting('table_striped', $theme), '#description' => t('Add zebra-striping to any table row within the <code>&lt;tbody&gt;</code>. <strong>Note:</strong> Striped tables are styled via the <code>:nth-child</code> CSS selector, which is not available in Internet Explorer 8.'));
    $form['general']['tables']['bootstrap_table_responsive'] = array('#type' => 'checkbox', '#title' => t('Responsive tables'), '#default_value' => bootstrap_setting('table_responsive', $theme), '#description' => t('Makes tables responsive by wrapping them in <code>.table-responsive</code> to make them scroll horizontally up to small devices (under 768px). When viewing on anything larger than 768px wide, you will not see any difference in these tables.'));
    // Components.
    $form['components'] = array('#type' => 'details', '#title' => t('Components'), '#group' => 'bootstrap');
    // Breadcrumbs.
    $form['components']['breadcrumbs'] = array('#type' => 'details', '#title' => t('Breadcrumbs'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['components']['breadcrumbs']['bootstrap_breadcrumb'] = array('#type' => 'select', '#title' => t('Breadcrumb visibility'), '#default_value' => bootstrap_setting('breadcrumb', $theme), '#options' => array(0 => t('Hidden'), 1 => t('Visible'), 2 => t('Only in admin areas')));
    $form['components']['breadcrumbs']['bootstrap_breadcrumb_home'] = array('#type' => 'checkbox', '#title' => t('Show "Home" breadcrumb link'), '#default_value' => bootstrap_setting('breadcrumb_home', $theme), '#description' => t('If your site has a module dedicated to handling breadcrumbs already, ensure this setting is enabled.'), '#states' => array('invisible' => array(':input[name="bootstrap_breadcrumb"]' => array('value' => 0))));
    $form['components']['breadcrumbs']['bootstrap_breadcrumb_title'] = array('#type' => 'checkbox', '#title' => t('Show current page title at end'), '#default_value' => bootstrap_setting('breadcrumb_title', $theme), '#description' => t('If your site has a module dedicated to handling breadcrumbs already, ensure this setting is disabled.'), '#states' => array('invisible' => array(':input[name="bootstrap_breadcrumb"]' => array('value' => 0))));
    // Navbar.
    $form['components']['navbar'] = array('#type' => 'details', '#title' => t('Navbar'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['components']['navbar']['bootstrap_navbar_position'] = array('#type' => 'select', '#title' => t('Navbar Position'), '#description' => t('Select your Navbar position.'), '#default_value' => bootstrap_setting('navbar_position', $theme), '#options' => array('static-top' => t('Static Top'), 'fixed-top' => t('Fixed Top'), 'fixed-bottom' => t('Fixed Bottom')), '#empty_option' => t('Normal'));
    $form['components']['navbar']['bootstrap_navbar_inverse'] = array('#type' => 'checkbox', '#title' => t('Inverse navbar style'), '#description' => t('Select if you want the inverse navbar style.'), '#default_value' => bootstrap_setting('navbar_inverse', $theme));
    // Region wells.
    $wells = array('' => t('None'), 'well' => t('.well (normal)'), 'well well-sm' => t('.well-sm (small)'), 'well well-lg' => t('.well-lg (large)'));
    $form['components']['region_wells'] = array('#type' => 'details', '#title' => t('Region wells'), '#description' => t('Enable the <code>.well</code>, <code>.well-sm</code> or <code>.well-lg</code> classes for specified regions. See: documentation on <a href=":wells" target="_blank">Bootstrap Wells</a>.', array(':wells' => 'http://getbootstrap.com/components/#wells')), '#collapsible' => TRUE, '#collapsed' => TRUE);
    // Get defined regions.
    $regions = system_region_list('bootstrap');
    foreach ($regions as $name => $title) {
        $form['components']['region_wells']['bootstrap_region_well-' . $name] = array('#title' => $title, '#type' => 'select', '#attributes' => array('class' => array('input-sm')), '#options' => $wells, '#default_value' => bootstrap_setting('region_well-' . $name, $theme));
    }
    // JavaScript settings.
    $form['javascript'] = array('#type' => 'details', '#title' => t('JavaScript'), '#group' => 'bootstrap');
    // Anchors.
    $form['javascript']['anchors'] = array('#type' => 'details', '#title' => t('Anchors'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#description' => t('This plugin is not able to be configured from the UI as it is severely broken. In an effort to balance not break backwards compatibility and to prevent new users from running into unforeseen issues, you must manually opt-in/out inside your theme\'s setting configuration file. Please see the following issue for more details: <a href=":url" target="_blank">Replace custom JS with the bootstrap-anchor plugin</a>', array(':url' => 'https://www.drupal.org/node/2462645')));
    $form['javascript']['anchors']['bootstrap_anchors_fix'] = array('#type' => 'checkbox', '#title' => t('Fix anchor positions'), '#default_value' => bootstrap_setting('anchors_fix', $theme), '#description' => t('Ensures anchors are correctly positioned only when there is margin or padding detected on the BODY element. This is useful when fixed navbar or administration menus are used.'), '#disabled' => TRUE);
    $form['javascript']['anchors']['bootstrap_anchors_smooth_scrolling'] = array('#type' => 'checkbox', '#title' => t('Enable smooth scrolling'), '#default_value' => bootstrap_setting('anchors_smooth_scrolling', $theme), '#description' => t('Animates page by scrolling to an anchor link target smoothly when clicked.'), '#states' => array('invisible' => array(':input[name="bootstrap_anchors_fix"]' => array('checked' => FALSE))), '#disabled' => TRUE);
    // Forms.
    $form['javascript']['forms'] = array('#type' => 'details', '#title' => t('Forms'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['javascript']['forms']['bootstrap_forms_has_error_value_toggle'] = array('#type' => 'checkbox', '#title' => t('Automatically remove error classes when values have been entered'), '#default_value' => bootstrap_setting('forms_has_error_value_toggle', $theme), '#description' => t('If an element has a <code>.has-error</code> class attached to it, enabling this will automatically remove that class when a value is entered. This feature compliments the "General > Forms > Make required elements display as an error" feature.'));
    // Popovers.
    $form['javascript']['popovers'] = array('#type' => 'details', '#title' => t('Popovers'), '#description' => t('Add small overlays of content, like those on the iPad, to any element for housing secondary information.'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['javascript']['popovers']['bootstrap_popover_enabled'] = array('#type' => 'checkbox', '#title' => t('Enable popovers.'), '#description' => t('Elements that have the <code>data-toggle="popover"</code> attribute set will automatically initialize the popover upon page load. <strong class="error text-error">WARNING: This feature can sometimes impact performance. Disable if pages appear to "hang" after initial load.</strong>'), '#default_value' => bootstrap_setting('popover_enabled', $theme));
    $form['javascript']['popovers']['options'] = array('#type' => 'details', '#title' => t('Options'), '#description' => t('These are global options. Each popover can independently override desired settings by appending the option name to <code>data-</code>. Example: <code>data-animation="false"</code>.'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#states' => array('visible' => array(':input[name="bootstrap_popover_enabled"]' => array('checked' => TRUE))));
    $form['javascript']['popovers']['options']['bootstrap_popover_animation'] = array('#type' => 'checkbox', '#title' => t('animate'), '#description' => t('Apply a CSS fade transition to the popover.'), '#default_value' => bootstrap_setting('popover_animation', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_html'] = array('#type' => 'checkbox', '#title' => t('HTML'), '#description' => t("Insert HTML into the popover. If false, jQuery's text method will be used to insert content into the DOM. Use text if you're worried about XSS attacks."), '#default_value' => bootstrap_setting('popover_html', $theme));
    $options = array('top', 'bottom', 'left', 'right', 'auto', 'auto top', 'auto bottom', 'auto left', 'auto right');
    $form['javascript']['popovers']['options']['bootstrap_popover_placement'] = array('#type' => 'select', '#title' => t('placement'), '#description' => t('Where to position the popover. When "auto" is specified, it will dynamically reorient the popover. For example, if placement is "auto left", the popover will display to the left when possible, otherwise it will display right.'), '#default_value' => bootstrap_setting('popover_placement', $theme), '#options' => array_combine($options, $options));
    $form['javascript']['popovers']['options']['bootstrap_popover_selector'] = array('#type' => 'textfield', '#title' => t('selector'), '#description' => t('If a selector is provided, tooltip objects will be delegated to the specified targets. In practice, this is used to enable dynamic HTML content to have popovers added. See <a href=":this" target="_blank">this</a> and <a href=":example" target="_blank">an informative example</a>.', array(':this' => 'https://github.com/twbs/bootstrap/issues/4215', ':example' => 'http://jsfiddle.net/fScua/')), '#default_value' => bootstrap_setting('popover_selector', $theme));
    $options = array('click', 'hover', 'focus', 'manual');
    $form['javascript']['popovers']['options']['bootstrap_popover_trigger'] = array('#type' => 'checkboxes', '#title' => t('trigger'), '#description' => t('How a popover is triggered.'), '#default_value' => bootstrap_setting('popover_trigger', $theme), '#options' => array_combine($options, $options));
    $form['javascript']['popovers']['options']['bootstrap_popover_trigger_autoclose'] = array('#type' => 'checkbox', '#title' => t('Auto-close on document click'), '#description' => t('Will automatically close the current popover if a click occurs anywhere else other than the popover element.'), '#default_value' => bootstrap_setting('popover_trigger_autoclose', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_title'] = array('#type' => 'textfield', '#title' => t('title'), '#description' => t("Default title value if \"title\" attribute isn't present."), '#default_value' => bootstrap_setting('popover_title', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_content'] = array('#type' => 'textfield', '#title' => t('content'), '#description' => t('Default content value if "data-content" or "data-target" attributes are not present.'), '#default_value' => bootstrap_setting('popover_content', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_delay'] = array('#type' => 'textfield', '#title' => t('delay'), '#description' => t('The amount of time to delay showing and hiding the popover (in milliseconds). Does not apply to manual trigger type.'), '#default_value' => bootstrap_setting('popover_delay', $theme));
    $form['javascript']['popovers']['options']['bootstrap_popover_container'] = array('#type' => 'textfield', '#title' => t('container'), '#description' => t('Appends the popover to a specific element. Example: "body". This option is particularly useful in that it allows you to position the popover in the flow of the document near the triggering element - which will prevent the popover from floating away from the triggering element during a window resize.'), '#default_value' => bootstrap_setting('popover_container', $theme));
    // Tooltips.
    $form['javascript']['tooltips'] = array('#type' => 'details', '#title' => t('Tooltips'), '#description' => t('Inspired by the excellent jQuery.tipsy plugin written by Jason Frame; Tooltips are an updated version, which don\'t rely on images, use CSS3 for animations, and data-attributes for local title storage. See <a href=":url" target="_blank">Bootstrap tooltips</a> for more documentation.', array(':url' => 'http://getbootstrap.com/javascript/#tooltips')), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['javascript']['tooltips']['bootstrap_tooltip_enabled'] = array('#type' => 'checkbox', '#title' => t('Enable tooltips'), '#description' => t('Elements that have the <code>data-toggle="tooltip"</code> attribute set will automatically initialize the tooltip upon page load. <strong class="error text-error">WARNING: This feature can sometimes impact performance. Disable if pages appear to "hang" after initial load.</strong>'), '#default_value' => bootstrap_setting('tooltip_enabled', $theme));
    $form['javascript']['tooltips']['options'] = array('#type' => 'details', '#title' => t('Options'), '#description' => t('These are global options. Each tooltip can independently override desired settings by appending the option name to <code>data-</code>. Example: <code>data-animation="false"</code>.'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#states' => array('visible' => array(':input[name="bootstrap_tooltip_enabled"]' => array('checked' => TRUE))));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_animation'] = array('#type' => 'checkbox', '#title' => t('animate'), '#description' => t('Apply a CSS fade transition to the tooltip.'), '#default_value' => bootstrap_setting('tooltip_animation', $theme));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_html'] = array('#type' => 'checkbox', '#title' => t('HTML'), '#description' => t("Insert HTML into the tooltip. If false, jQuery's text method will be used to insert content into the DOM. Use text if you're worried about XSS attacks."), '#default_value' => bootstrap_setting('tooltip_html', $theme));
    $options = array('top', 'bottom', 'left', 'right', 'auto', 'auto top', 'auto bottom', 'auto left', 'auto right');
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_placement'] = array('#type' => 'select', '#title' => t('placement'), '#description' => t('Where to position the tooltip. When "auto" is specified, it will dynamically reorient the tooltip. For example, if placement is "auto left", the tooltip will display to the left when possible, otherwise it will display right.'), '#default_value' => bootstrap_setting('tooltip_placement', $theme), '#options' => array_combine($options, $options));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_selector'] = array('#type' => 'textfield', '#title' => t('selector'), '#description' => t('If a selector is provided, tooltip objects will be delegated to the specified targets.'), '#default_value' => bootstrap_setting('tooltip_selector', $theme));
    $options = array('click', 'hover', 'focus', 'manual');
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_trigger'] = array('#type' => 'checkboxes', '#title' => t('trigger'), '#description' => t('How a tooltip is triggered.'), '#default_value' => bootstrap_setting('tooltip_trigger', $theme), '#options' => array_combine($options, $options));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_delay'] = array('#type' => 'textfield', '#title' => t('delay'), '#description' => t('The amount of time to delay showing and hiding the tooltip (in milliseconds). Does not apply to manual trigger type.'), '#default_value' => bootstrap_setting('tooltip_delay', $theme));
    $form['javascript']['tooltips']['options']['bootstrap_tooltip_container'] = array('#type' => 'textfield', '#title' => t('container'), '#description' => t('Appends the tooltip to a specific element. Example: "body"'), '#default_value' => bootstrap_setting('tooltip_container', $theme));
    // Advanced settings.
    $form['advanced'] = array('#type' => 'details', '#title' => t('Advanced'), '#group' => 'bootstrap');
    // BootstrapCDN.
    bootstrap_cdn_provider_settings_form($form, $form_state, $theme);
}
Example #25
0
/**
 * Preprocess form_element.
 */
function bootstrap_preprocess_form_element(&$variables)
{
    $element =& $variables['element'];
    $title_display = $element['#title_display'];
    $name = !empty($element['#name']) ? $element['#name'] : FALSE;
    $type = !empty($element['#type']) ? $element['#type'] : FALSE;
    $checkbox = $type && $type === 'checkbox';
    $radio = $type && $type === 'radio';
    $has_tooltip = FALSE;
    // This function is invoked as theme wrapper, but the rendered form element
    // may not necessarily have been processed by Drupal::formBuilder()->doBuildForm().
    $element += array('#title_display' => 'before');
    // Check for errors and set correct error class.
    $formState = new FormState();
    if (isset($element['#parents']) && $formState->getError($element) || !empty($element['#required']) && bootstrap_setting('forms_required_has_error')) {
        $variables['has_error'] = TRUE;
    }
    if (!empty($element['#autocomplete_route_name']) && Drupal::PathValidator($element['#autocomplete_route_name'])) {
        $variables['is_autocomplete'] = TRUE;
    }
    // See http://getbootstrap.com/css/#forms-controls.
    if (isset($element['#type'])) {
        if ($radio) {
            $variables['is_radio'] = TRUE;
        } elseif ($checkbox) {
            $variables['is_checkbox'] = TRUE;
        } elseif ($type != 'hidden') {
            $variables['is_form_group'] = TRUE;
        }
    }
    // If #title is not set, we don't display any label or required marker.
    if (!isset($element['#title'])) {
        $element['#title_display'] = 'none';
    }
    $variables['title_display'] = $element['#title_display'];
    // Add label_display and label variables to template.
    $variables['label_display'] = $element['#title_display'];
    // Place single checkboxes and radios in the label field.
    if (($checkbox || $radio) && $title_display != 'none' && $title_display != 'invisible') {
        $variables['label']['#children'] = $variables['children'];
        unset($variables['children']);
        unset($variables['description']);
        // Pass the label attributes to the label, if available.
        if (isset($variables['element']['#label_attributes'])) {
            $variables['label']['#label_attributes'] = $variables['element']['#label_attributes'];
        }
    }
    // Create variables for #input_group and #input_group_button flags.
    if (isset($element['#input_group'])) {
        $variables['input_group'] = $element['#input_group'];
    }
    if (isset($element['#input_group_button'])) {
        $variables['input_group_button'] = $element['#input_group_button'];
    }
    $prefix = '';
    $suffix = '';
    if (isset($element['#field_prefix']) || isset($element['#field_suffix'])) {
        // Determine if "#input_group" was specified.
        if (!empty($element['#input_group'])) {
            $prefix = array('#markup' => '<div class="input-group">' . (isset($element['#field_prefix']) ? '<span class="input-group-addon">' . $element['#field_prefix'] . '</span>' : ''));
            $suffix = array('#markup' => (isset($element['#field_suffix']) ? '<span class="input-group-addon">' . $element['#field_suffix'] . '</span>' : '') . '</div>');
        } elseif (!empty($element['#input_group_button'])) {
            $prefix = array('#markup' => '<div class="input-group">' . (isset($element['#field_prefix']) ? '<span class="input-group-btn">' . $element['#field_prefix'] . '</span>' : ''));
            $suffix = array('#markup' => (isset($element['#field_suffix']) ? '<span class="input-group-btn">' . $element['#field_suffix'] . '</span>' : '') . '</div>');
        }
        $render = \Drupal::service('renderer');
        $variables['prefix'] = $render->render($prefix);
        $variables['suffix'] = $render->render($suffix);
    } else {
        $variables['prefix'] = '';
        $variables['suffix'] = '';
    }
}
/**
 * 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');
    if (empty($element['#wrapper_attributes'])) {
        $element['#wrapper_attributes'] = array();
    }
    $wrapper_attributes =& $element['#wrapper_attributes'];
    // Add element #id for #type 'item'.
    if (isset($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';
    }
    if (!empty($element['#type'])) {
        $wrapper_attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
    }
    if (!empty($element['#name'])) {
        $wrapper_attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
    }
    // Add a class for disabled elements to facilitate cross-browser styling.
    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';
    }
    $wrapper_attributes['class'][] = 'form-item';
    // See http://getbootstrap.com/css/#forms-controls.
    if (isset($element['#type'])) {
        if ($element['#type'] === 'radio') {
            $wrapper_attributes['class'][] = 'radio';
            $is_radio = TRUE;
        } elseif ($element['#type'] === 'checkbox') {
            $wrapper_attributes['class'][] = 'checkbox';
            $is_checkbox = TRUE;
        } elseif ($element['#type'] !== 'hidden') {
            $wrapper_attributes['class'][] = 'form-group';
        }
    }
    $tooltip_description = !empty($element['#description']) && _bootstrap_tooltip_description($element['#description']);
    if ($tooltip_description && ($element['#type'] === 'checkbox' || $element['#type'] === 'radio' || $element['#type'] === 'checkboxes' || $element['#type'] === 'radios')) {
        $wrapper_attributes['title'] = $element['#description'];
        $wrapper_attributes['data-toggle'] = 'tooltip';
    }
    $output = '<div' . drupal_attributes($wrapper_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>';
        } elseif (!empty($element['#input_group_button'])) {
            $prefix .= '<div class="input-group">';
            $prefix .= isset($element['#field_prefix']) ? '<span class="input-group-btn">' . $element['#field_prefix'] . '</span>' : '';
            $suffix .= isset($element['#field_suffix']) ? '<span class="input-group-btn">' . $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) {
                $variables['#children'] = $prefix . $element['#children'] . ' ' . $suffix;
            } else {
                $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;
    }
    if (!empty($element['#description']) && !$tooltip_description && empty($element['#attributes']['title'])) {
        $output .= '<p class="help-block">' . $element['#description'] . "</p>\n";
    }
    $output .= "</div>\n";
    return $output;
}
Example #27
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);
}