You are here

panels_tabs.module in Panels Tabs 6

Same filename and directory in other branches
  1. 5 panels_tabs.module
  2. 7.2 panels_tabs.module
  3. 7 panels_tabs.module

Definition of the 'tabs' panel style.

File

panels_tabs.module
View source
<?php

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

//----------------------------------------------------------------------------

// Panels hooks.

/**
 * Implements hook_ctools_plugin_directory().
 */
function panels_tabs_ctools_plugin_directory($module, $plugin) {
  if ($module == 'page_manager' || $module == 'panels') {
    return 'plugins/' . $plugin;
  }
}

/**
 * Implements hook_ctools_plugin_api().
 */
function panels_tabs_ctools_plugin_api($module, $api) {
  if ($module == 'panels' && $api == 'styles') {

    // Check and return correct style version
    return array(
      'version' => panels_tabs_style_version(),
    );
  }
}

/**
 * Implements hook_panels_pre_render().
 */
function panels_tabs_panels_pre_render($display, $renderer = NULL) {

  // Don't run if we are using an old version of panels or legacy mode
  if (empty($renderer)) {
    return;
  }
  elseif (panels_tabs_style_version() == 2) {
    $tabs_regions = array();

    // Check if the tabs style has been applied to entire panel
    $global_style = !empty($renderer->display->panel_settings['style']) ? $renderer->display->panel_settings['style'] : '';

    // Get the list of regions for the panel
    $regions = panels_get_regions($renderer->plugins['layout'], $renderer->display);

    // Find out which regions are using the tabs style and add to an array
    foreach ($regions as $region_id => $title) {
      $settings = !empty($renderer->display->panel_settings[$region_id]) ? $renderer->display->panel_settings[$region_id] : array();
      if ($global_style == 'tabs' && (empty($settings['style']) || $settings['style'] == -1)) {
        $tabs_regions[] = $region_id;
      }
      elseif (!empty($settings['style']) && $settings['style'] == 'tabs') {
        $tabs_regions[] = $region_id;
      }
    }

    // Go through all the panes and mark those that are in a tab region.
    foreach ($renderer->display->content as $pane_id => $pane) {
      if (in_array($pane->panel, $tabs_regions)) {
        $renderer->display->content[$pane_id]->region_style = 'tabs';
      }
    }
  }
}

/**
 * Implements hook_panels_pane_content_alter().
 */
function panels_tabs_panels_pane_content_alter($content, $pane, $args, $context) {

  // Don't run if we are using legacy mode
  if (panels_tabs_style_version() == 2) {
    if (!empty($pane->region_style) && $pane->region_style == 'tabs' && isset($content->title)) {
      $pane->tab_title = $content->title;

      // Set the original title in case it is required to provide the panel title
      if (!empty($content->title) && $content->title != '<none>') {
        $content->original_title = $content->title;
      }
      unset($content->title);
    }
  }
}

/**
 * Implementation of hook_theme()
 */
function panels_tabs_theme() {
  return array(
    'panels_tabs_title' => array(
      'arguments' => array(
        'title' => NULL,
      ),
    ),
  );
}

/**
 * Determine which style version we shoud declare.
 */
function panels_tabs_style_version() {

  // If ctools api version is greater than 1.7 then we should return version 2
  $new = version_compare(PANELS_REQUIRED_CTOOLS_API, 1.7, '>=');
  return $new ? 2 : 1;
}

/**
 * Return rendered title.
 *
 * @themable
 */
function theme_panels_tabs_title($title) {
  return "<h3 class=\"pane-title\">" . $title . "</h3>\n";
}

//----------------------------------------------------------------------------

// Private functions.

/**
 * Adds the .js file only once per page load.
 */
function _panels_tabs_add_js($id, $filling_tabs) {
  static $added = FALSE;
  static $settings_added;

  // Include the JavaScript once per page.
  if (!$added) {
    drupal_add_js(drupal_get_path('module', 'panels_tabs') . '/panels_tabs.js');
    $added = TRUE;
  }

  // Store the JavaScript settings for every panel that uses this style.
  if (!isset($settings_added[$id])) {
    drupal_add_js(array(
      'panelsTabs' => array(
        $id => array(
          'fillingTabs' => isset($filling_tabs) ? $filling_tabs : 'disabled',
        ),
      ),
    ), 'setting');
    $settings_added[$id] = TRUE;
  }
}

Functions

Namesort descending Description
panels_tabs_ctools_plugin_api Implements hook_ctools_plugin_api().
panels_tabs_ctools_plugin_directory Implements hook_ctools_plugin_directory().
panels_tabs_panels_pane_content_alter Implements hook_panels_pane_content_alter().
panels_tabs_panels_pre_render Implements hook_panels_pre_render().
panels_tabs_style_version Determine which style version we shoud declare.
panels_tabs_theme Implementation of hook_theme()
theme_panels_tabs_title Return rendered title.
_panels_tabs_add_js Adds the .js file only once per page load.