You are here

function tabs_process_tabset in Javascript Tools 5

Process a tabset prior to rendering.

File

tabs/tabs.module, line 94
API for creating tabbed pages.

Code

function tabs_process_tabset($element) {
  static $names = array();

  // Ensure name is unique.
  $i = 0;

  // Assign a name, reading from the first parent (the key of this tabset element).
  $name = $element['#tabset_name'] = $element['#tabset_name'] ? $element['#tabset_name'] : (isset($element['#parents']) && count($element['#parents']) ? $element['#parents'][0] : 'tabset');

  // In case we have duplicate names...
  while (in_array($element['#tabset_name'], $names)) {
    $element['#tabset_name'] = $name . $i;
    $i++;
  }
  $names[] = $element['#tabset_name'];

  // Add class.
  if (!isset($element['#attributes'])) {
    $element['#attributes'] = array();
  }
  $element['#attributes']['class'] = (isset($element['#attributes']['class']) ? $element['#attributes']['class'] . ' ' : '') . 'drupal-tabs' . (isset($element['#tabs_navigation']) && $element['#tabs_navigation'] ? ' tabs-navigation' : '');
  $index = 1;

  // Sort the elements by weight.
  // Because uasort doesn't keep the original order for equal values,
  // we assign a nominal weight to all elements.
  foreach (element_children($element) as $count => $key) {
    if (!isset($element[$key]['#weight']) || $element[$key]['#weight'] == 0) {
      $element[$key]['#weight'] = $count / 1000;
    }
  }
  uasort($element, '_element_sort');
  foreach (element_children($element) as $key) {
    if (isset($element[$key]['#type']) && $element[$key]['#type'] == 'tabpage') {

      // Display any #description before the #content.
      $element[$key]['#content'] = ($element[$key]['#description'] ? '<div class="description">' . $element[$key]['#description'] . '</div>' : '') . $element[$key]['#content'];
      $element[$key]['#tabset_name'] = $element['#tabset_name'];
      $element[$key]['#index'] = $index++;
    }
  }
  return $element;
}