You are here

function theme_pagerer in Pagerer 7

Pagerer multi-pane pager.

When Pagerer is set to override Drupal built-in pager, theme('pager', ...) calls are redirected here via _pagerer_override_theme_pager(). The theme can also be invoked directly by calls to theme('pagerer', ...). In such case, the theme variables to be used in each pane either have to be passed explicitly or loaded from a preset configuration through the 'preset' key in the variables.

4 theme calls to theme_pagerer()
pagerer_example_page in ./pagerer_example.module
Build the pagerer example.
pagerer_preset_form in ./pagerer.admin.inc
Preset edit form.
theme_pagerer_preset_list in ./pagerer.admin.inc
Render a table with the presets lists.
_pagerer_override_theme_pager in ./pagerer.module
Pagerer's wrapper for overriden standard 'pager' theme calls.

File

./pagerer.module, line 536
Pagerer

Code

function theme_pagerer($variables) {

  // If forced to use core pager, call it and return straight away.
  if (isset($variables['preset']) and $variables['preset'] == 'core') {
    $common_theme = drupal_common_theme();
    $core_vars = array_merge(array(
      'tags' => $common_theme['pager']['variables']['tags'],
      'element' => $common_theme['pager']['variables']['element'],
      'parameters' => $common_theme['pager']['variables']['parameters'],
      'quantity' => $common_theme['pager']['variables']['quantity'],
    ), $variables);
    return _pagerer_execute_overriden_theme_pager($core_vars);
  }

  // Get preset panes setup if specified.
  if (isset($variables['preset']) and !empty($variables['preset'])) {
    $preset = _pagerer_get_preset($variables['preset']);
  }
  else {
    $preset = array();
  }

  // Get core variables.
  $core_vars = array_intersect_key($variables, array(
    'tags' => NULL,
    'element' => NULL,
    'parameters' => NULL,
    'quantity' => NULL,
  ));

  // Fully qualify all panes.
  foreach (array(
    'left',
    'center',
    'right',
  ) as $p) {
    $pane_key = $p . '_pane';

    // Determine pane's theme name.
    if (isset($preset[$pane_key]['theme_name'])) {
      $variables[$pane_key]['theme_name'] = $preset[$pane_key]['theme_name'];
    }
    elseif (!isset($variables[$pane_key]['theme_name'])) {
      switch ($p) {
        case 'left':
        case 'right':
          $variables[$pane_key]['theme_name'] = 'none';
          break;
        case 'center':
          $variables[$pane_key]['theme_name'] = 'pagerer_standard';
          break;
      }
    }

    // Determine pane's theme variables.
    if ($variables[$pane_key]['theme_name'] != 'none') {
      $tmp = isset($variables[$pane_key]['theme_variables']) ? $variables[$pane_key]['theme_variables'] : array();
      if (isset($preset[$pane_key]['theme_variables'])) {
        $tmp = array_merge_recursive($preset[$pane_key]['theme_variables'], $tmp);
      }
      $variables[$pane_key]['theme_variables'] = array_merge($core_vars, $tmp);
    }
    else {
      $variables[$pane_key]['theme_variables'] = array();
    }
  }

  // Check if pager is needed; if not, return immediately.
  // It is the lowest required number of pages in any of the panes.
  global $pager_total, $pager_limits;
  if (empty($pager_total[$variables['element']])) {
    $pager_total[$variables['element']] = 0;
  }
  $page_restriction = min(_pagerer_get_page_restriction($variables['left_pane']['theme_variables']), _pagerer_get_page_restriction($variables['center_pane']['theme_variables']), _pagerer_get_page_restriction($variables['right_pane']['theme_variables']));
  if ($pager_total[$variables['element']] < $page_restriction) {
    return NULL;
  }

  // Build render array.
  $panes = array();
  foreach (array(
    'left',
    'center',
    'right',
  ) as $p) {
    $pane_key = $p . '_pane';
    if ($variables[$pane_key]['theme_name'] != 'none') {
      $panes[$pane_key] = array(
        'data' => theme($variables[$pane_key]['theme_name'], $variables[$pane_key]['theme_variables']),
        'class' => array(
          'pagerer',
          'pagerer-' . $p,
        ),
      );
    }
    else {
      $panes[$pane_key] = NULL;
    }
  }

  // Render a 1 row * 3 columns table, where each cell is a 'pane'
  // holding a rendered pager. See pagerer.css for specific styling.
  $row = array(
    'data' => $panes,
    'no_striping' => TRUE,
  );
  $output = theme('table', array(
    'header' => array(),
    'rows' => array(
      $row,
    ),
    'attributes' => array(
      'class' => array(
        'pagerer',
      ),
    ),
    'caption' => NULL,
    'colgroups' => NULL,
    'sticky' => FALSE,
    'empty' => NULL,
  ));
  return $output;
}