You are here

function template_preprocess_bootstrap_fieldgroup_nav in Bootstrap fieldgroup 7

Implements template_preprocess_bootstrap_tabs().

Parameters

$variables:

File

./bootstrap_fieldgroup.module, line 346
Module file for the bootstrap_fieldgroup module.

Code

function template_preprocess_bootstrap_fieldgroup_nav(&$variables) {
  $group =& $variables['group'];
  $variables['wrapper_classes'] = $variables['group']->classes;
  $variables['wrapper_classes'] .= ' bootstrap-nav-wrapper';
  $variables['flip'] = FALSE;
  if ($group->format_settings['instance_settings']['bootstrap_orientation']) {
    switch ($group->format_settings['instance_settings']['bootstrap_orientation']) {
      case 1:
        $variables['wrapper_classes'] .= ' tabs-right';
        break;
      case 2:
        $variables['wrapper_classes'] .= ' tabs-below';
        $variables['flip'] = TRUE;
        break;
      case 3:
        $variables['wrapper_classes'] .= ' tabs-left';
        break;
      default:
    }
  }
  $variables['nav_classes'] = $variables['group']->classes;
  switch ($group->format_settings['instance_settings']['bootstrap_nav_type']) {
    case 'tabs':
      $variables['nav_classes'] .= ' nav-tabs';
      break;
    case 'pills':
      $variables['nav_classes'] .= ' nav-pills';
      break;
    default:
  }
  if ($group->format_settings['instance_settings']['bootstrap_stacked']) {
    $variables['nav_classes'] .= ' nav-stacked';
  }
  $variables['pane_classes'] = $variables['group']->classes;
  uasort($variables['items'], 'element_sort');
  foreach ($variables['items'] as $key => $item) {

    // Check if item is not empty and we have access to it.
    if ($item && (!isset($item['#access']) || $item['#access'])) {
      if (!empty($item['#group'])) {
        $label = $item['#group']->label;
      }
      else {
        if (!empty($item['#title'])) {
          $label = $item['#title'];
        }
      }
      $id = drupal_html_id('bootstrap-fieldgroup-nav-item--' . $label);

      // Is an explicit nav item?
      if (!empty($item['#type']) && 'bootstrap_fieldgroup_nav_item' == $item['#type']) {
        $classes = $item['#group']->classes;
      }
      else {
        $classes = '';
      }
      $variables['navs'][] = array(
        'content' => l(check_plain(t($label)), NULL, array(
          'attributes' => array(
            'data-toggle' => 'tab',
          ),
          'fragment' => $id,
          'external' => TRUE,
          'html' => TRUE,
        )),
        'classes' => $classes,
      );
      $variables['panes'][] = array(
        'id' => $id,
        'content' => drupal_render($item),
      );
    }
  }

  // Config?
  $variables['active'] = 0;
  $variables['is_empty'] = empty($variables['navs']) && empty($variables['panes']);
  $variables['is_single'] = count($variables['navs']) == 1;
}