function brainstorm_theme_pager in Brainstorm profile 7
Implements hook_pager().
File
- themes/
brainstorm_theme/ template.php, line 148 - Process theme data.
Code
function brainstorm_theme_pager($variables) {
$tags = $variables['tags'];
$element = $variables['element'];
$parameters = $variables['parameters'];
$quantity = 2;
global $pager_page_array, $pager_total;
// Calculate various markers within this pager piece:
// Middle is used to "center" pages around the current page.
$pager_middle = ceil($quantity / 2);
// Current is the page we are currently paged to.
$pager_current = $pager_page_array[$element] + 1;
// First is the first page listed by this pager piece (re quantity)
$pager_first = $pager_current - $pager_middle + 1;
// Last is the last page listed by this pager piece (re quantity)
$pager_last = $pager_current + $quantity - $pager_middle;
// Max is the maximum page number.
$pager_max = $pager_total[$element];
// End of marker calculations.
// Prepare for generation loop.
$i = $pager_first;
if ($pager_last > $pager_max) {
// Adjust "center" if at end of query.
$i = $i + ($pager_max - $pager_last);
$pager_last = $pager_max;
}
if ($i <= 0) {
// Adjust "center" if at start of query.
$pager_last = $pager_last + (1 - $i);
$i = 1;
}
// End of generation loop preparation.
$li_first = theme('pager_first', [
'text' => t('<'),
'element' => $element,
'parameters' => $parameters,
]);
$li_last = theme('pager_last', [
'text' => t('>'),
'element' => $element,
'parameters' => $parameters,
]);
if ($pager_total[$element] > 1) {
if ($li_first) {
$items[] = [
'class' => [
'pager-first',
],
'data' => $li_first,
];
}
// When there is more than one page, create the pager list.
if ($i != $pager_max) {
// Now generate the actual pager piece.
for (; $i <= $pager_last && $i <= $pager_max; $i++) {
if ($i < $pager_current && $i != 1) {
$items[] = [
'class' => [
'pager-item',
],
'data' => theme('pager_previous', [
'text' => $i,
'element' => $element,
'interval' => $pager_current - $i,
'parameters' => $parameters,
]),
];
}
if ($i == $pager_current) {
$items[] = [
'class' => [
'pager-current',
],
'data' => $i,
];
}
if ($i > $pager_current && ($i != $pager_total[$element] || $pager_current == $pager_total[$element] - 1)) {
$items[] = [
'class' => [
'pager-item',
],
'data' => theme('pager_next', [
'text' => $i,
'element' => $element,
'interval' => $i - $pager_current,
'parameters' => $parameters,
]),
];
}
}
if ($i < $pager_max) {
$items[] = [
'class' => [
'pager-ellipsis',
],
'data' => '…',
];
$items[] = [
'class' => [
'pager-first',
],
'data' => theme('pager_last', [
'text' => t($pager_total[$element]),
'element' => $element,
'parameters' => $parameters,
]),
];
}
}
if ($li_last) {
$items[] = [
'class' => [
'pager-last',
],
'data' => $li_last,
];
}
return '<h2 class="element-invisible">' . t('Pages') . '</h2>' . theme('item_list', [
'items' => $items,
'attributes' => [
'class' => [
'pager',
],
],
]);
}
}