You are here

bootstrap_quicktabs.module in Bootstrap Quick Tabs 7

Same filename and directory in other branches
  1. 8 bootstrap_quicktabs.module

Provides Bootstrap's tab styles to the Quicktabs module. Adapted from the re_quicktabs_foundation module.

File

bootstrap_quicktabs.module
View source
<?php

/**
 * @file
 * Provides Bootstrap's tab styles to the Quicktabs module. Adapted from the
 * re_quicktabs_foundation module.
 *
 * @see https://bitbucket.org/reyebrow/re_quicktabs_foundation
 */

/**
 * Implements hook_quicktabs_renderers().
 */
function bootstrap_quicktabs_quicktabs_renderers() {
  $info = array();
  $path = drupal_get_path('module', 'bootstrap_quicktabs');
  $info['bootstrap_tabs'] = array(
    'path' => $path,
    'handler' => array(
      'file' => 'BootstrapQuickTabs.inc',
      'class' => 'BootstrapQuickTabs',
    ),
  );
  $info['bootstrap_accordion'] = array(
    'path' => $path,
    'handler' => array(
      'file' => 'BootstrapAccordion.inc',
      'class' => 'BootstrapAccordion',
    ),
  );
  return $info;
}

/**
 * Implements hook_theme().
 */
function bootstrap_quicktabs_theme() {
  return array(
    'bootstrap_tabs' => array(
      'render element' => 'element',
    ),
    'bootstrap_tabs_tabset' => array(
      'render element' => 'tabset',
    ),
    'bootstrap_accordion' => array(
      'render element' => 'element',
    ),
  );
}

/**
 * Theme function to output tablinks for Foundation style tabs.
 *
 * @ingroup themeable
 */
function theme_bootstrap_tabs_tabset($settings) {

  // Empty set of tabs:
  $variables = array(
    'items' => array(),
    'title' => '',
    'type' => 'ul',
    'attributes' => array(),
  );
  foreach (element_children($settings['tabset']['tablinks']) as $key) {
    if (is_array($settings['tabset']['tablinks'])) {
      $tab = array();
      if ($key == $settings['tabset']['#options']['active']) {
        $tab['class'] = array(
          'active',
        );
      }
      $tab['data'] = drupal_render($settings['tabset']['tablinks'][$key]);
      $tab['role'] = 'presentation';
      $variables['items'][] = $tab;
    }
  }
  $classes = array(
    'nav',
    'nav-' . $settings['tabset']['#options']['style'],
  );
  if ($settings['tabset']['#options']['position'] == 'justified' || $settings['tabset']['#options']['position'] == 'stacked') {
    $classes[] = ' nav-' . $settings['tabset']['#options']['position'];
  }
  $variables['attributes']['class'] = $classes;
  return theme('item_list', $variables);
}

/**
 * Theme function to output content for Bootstrap style tabs.
 *
 * @ingroup themeable
 */
function theme_bootstrap_tabs($variables) {

  // Prepare various information we need:
  //
  // Set aside the 'element' from the array for convenience:
  $element = $variables['element'];

  // Figure out the output pattern--we need to reverse the order of tabs and
  // panes if this is the 'below' kind of tabs:
  $output_pattern = $element['tabs']['#options']['position'] != 'below' ? '<div%1$s>%2$s%3$s</div>' : '<div%1$s>%3$s%2$s</div>';

  // Prepare the tabs:
  $tabs = drupal_render($element['tabs']);

  // Prepare the panes:
  $panes = '<div class="tab-content">';
  foreach ($element['panes'] as $pane) {
    $panes .= drupal_render($pane);
  }
  $panes .= '</div>';

  // Build and return the output:
  return sprintf($output_pattern, drupal_attributes($element['#options']['attributes']), $tabs, $panes);
}

Functions

Namesort descending Description
bootstrap_quicktabs_quicktabs_renderers Implements hook_quicktabs_renderers().
bootstrap_quicktabs_theme Implements hook_theme().
theme_bootstrap_tabs Theme function to output content for Bootstrap style tabs.
theme_bootstrap_tabs_tabset Theme function to output tablinks for Foundation style tabs.