You are here

tabs.inc in Panels Tabs 7

Same filename and directory in other branches
  1. 6 plugins/styles/tabs.inc
  2. 7.2 plugins/styles/tabs.inc

Definition of the 'Tabs' panel style.

File

plugins/styles/tabs.inc
View source
<?php

/**
 * @file
 * Definition of the 'Tabs' panel style.
 */

// Plugin definition
$plugin = array(
  'title' => t('Tabs'),
  'description' => t('Show panel panes in a region as tabs.'),
  'render region' => 'panels_tabs_style_render_region',
);

/**
 * Render callback.
 *
 * @ingroup themeable
 */
function theme_panels_tabs_style_render_region($vars) {
  $display = $vars['display'];
  $region_id = $vars['region_id'];
  $owner_id = $vars['owner_id'];
  $panes = $vars['panes'];
  $tab_id = 'tabs-' . $owner_id . '-' . $region_id;
  $element = array(
    '#prefix' => '<div id="' . $tab_id . '">',
    '#suffix' => '</div>',
    '#attached' => array(
      'library' => array(
        array(
          'system',
          'ui.tabs',
        ),
      ),
      'js' => array(
        drupal_get_path('module', 'panels_tabs') . '/js/panels_tabs.js' => array(
          'type' => 'file',
        ),
      ),
    ),
  );
  $settings = array();
  $settings['panelsTabs']['tabsID'][] = $tab_id;
  $element['#attached']['js'][] = array(
    'type' => 'setting',
    'data' => $settings,
  );

  // Get the pane titles.
  $items = array();
  $delta = 1;
  if (isset($display->panels[$region_id])) {
    foreach ($display->panels[$region_id] as $pane_id) {

      // Make sure the pane exists.
      if (!empty($panes[$pane_id])) {
        $title = panels_tabs_pane_titles($display->did, $pane_id);
        $title = $title ? $title : t('Tab @delta', array(
          '@delta' => $delta,
        ));
        $items[] = '<a href="#' . $tab_id . '-' . $delta . '">' . $title . '</a>';
        ++$delta;
      }
    }
  }
  if ($delta === 1) {

    // No tabs to show, the tabs wrapper must not be rendered.
    return '';
  }
  $element['tabs_title'] = array(
    '#theme' => 'item_list',
    '#items' => $items,
  );
  $items = array();
  $delta = 1;
  foreach ($panes as $pane_id => $item) {
    $element['tabs_content'][$pane_id] = array(
      '#prefix' => '<div id="' . $tab_id . '-' . $delta . '">',
      '#suffix' => '</div>',
      '#markup' => $item,
    );
    ++$delta;
  }
  return drupal_render($element);
}

Functions

Namesort descending Description
theme_panels_tabs_style_render_region Render callback.