diff --git custom_pagers.admin.inc custom_pagers.admin.inc index 06840a3..07a8910 100644 --- custom_pagers.admin.inc +++ custom_pagers.admin.inc @@ -197,6 +197,18 @@ function custom_pagers_form($form, &$form_state, $pid = NULL) { '#description' => t("The natural list view ordering for an archive is the opposite of the natural 'previous/next' order for a pager. As such, reversing the pager list is useful when using a single view for paging and other sorted lists (pages, blocks, etc)."), '#default_value' => $pid ? $pager->reverse_list : NULL, ); + $form['node_list']['wrap'] = array( + '#type' => 'select', + '#title' => t('Wrapping'), + '#empty_option' => t('- No wrapping -'), + '#options' => array( + 'first' => t('Before the first item'), + 'last' => t('After the last item'), + 'both' => t('Both ways'), + ), + '#description' => t('Wrapping allows to jump from the first item to the last one and/or from the last item to the first one.'), + '#default_value' => $pid ? $pager->wrap : NULL, + ); $form['buttons']['submit'] = array( '#type' => 'submit', diff --git custom_pagers.install custom_pagers.install index 82245e0..0fcb32d 100644 --- custom_pagers.install +++ custom_pagers.install @@ -72,8 +72,28 @@ function custom_pagers_schema() { 'size' => 'tiny', 'description' => 'A boolean flag indicating that this {custom_pager} should be displayed in reverse order.', ), + 'wrap' => array( + 'type' => 'varchar', + 'length' => 16, + 'not null' => TRUE, + 'default' => '', + 'description' => 'Indicates how this {custom_pager} should wrap at the first and/or last item.', + ), ), 'primary key' => array('pid'), ); return $schema; } + +function custom_pagers_update_7000() { + if (!db_field_exists('custom_pager', 'wrap')) { + $schema_update = array( + 'type' => 'varchar', + 'length' => 16, + 'not null' => TRUE, + 'default' => '', + 'description' => 'Indicates how this {custom_pager} should wrap at the first and/or last item.', + ); + db_add_field('custom_pager', 'wrap', $schema_update); + } +} diff --git custom_pagers.module custom_pagers.module index 3d25e05..645d4e8 100644 --- custom_pagers.module +++ custom_pagers.module @@ -335,7 +335,17 @@ function template_preprocess_custom_pager(&$vars) { drupal_add_css(drupal_get_path('module', 'custom_pagers') . '/custom_pagers.css'); $node = $vars['node']; $pager = $vars['pager']; - $nav = $vars['nav_array']; + $nav = &$vars['nav_array']; + + if (count($nav['full_list']) > 1) { + // Handle wrapping, if enabled. + if (empty($nav['prev']) && ($pager->wrap == 'first' || $pager->wrap == 'both')) { + $nav['prev'] = end($nav['full_list']); + } + if (empty($nav['next']) && ($pager->wrap == 'last' || $pager->wrap == 'both')) { + $nav['next'] = reset($nav['full_list']); + } + } $vars['previous'] = !empty($nav['prev']) ? l('‹ ' . t('previous'), 'node/' . $nav['prev']) : ''; $vars['key'] = t('@count of @count_total', array('@count' => ($nav['current_index'] + 1), '@count_total' => count($nav['full_list'])));