diff --git includes/plugins.inc includes/plugins.inc index e8f409a..c0abdbd 100644 --- includes/plugins.inc +++ includes/plugins.inc @@ -288,6 +288,33 @@ function views_views_plugins() { 'help topic' => 'exposed-form-input-required', ), ), + 'pager' => array( + 'parent' => array( + 'no ui' => TRUE, + 'handler' => 'views_plugin_pager', + 'parent' => '', + 'uses options' => TRUE, + ), + 'none' => array( + 'title' => t('None'), + 'help' => t("Don't use Pager"), + 'handler' => 'views_plugin_pager_none', + 'help topic' => 'pager-none', + ), + 'mini' => array( + 'title' => t('Mini'), + 'help' => t('Mini Pager'), + 'handler' => 'views_plugin_pager_mini', + 'help topic' => 'pager-mini', + ), + 'full' => array( + 'title' => t('Full'), + 'help' => t('Full pager'), + 'handler' => 'views_plugin_pager_full', + 'help topic' => 'pager-full', + 'uses options' => TRUE, + ), + ), ); } diff --git plugins/views_plugin_display.inc plugins/views_plugin_display.inc index 08f5a93..d007bd0 100644 --- plugins/views_plugin_display.inc +++ plugins/views_plugin_display.inc @@ -113,10 +113,8 @@ class views_plugin_display extends views_plugin { * Does the display have a pager enabled? */ function use_pager() { - if (!empty($this->definition['use pager'])) { - return $this->get_option('use_pager'); - } - return FALSE; + $pager = $this->get_pager_plugin(); + return $pager->use_pager(); } /** @@ -182,7 +180,7 @@ class views_plugin_display extends views_plugin { 'empty' => array('empty', 'empty_format'), 'use_ajax' => array('use_ajax'), 'items_per_page' => array('items_per_page', 'offset', 'use_pager', 'pager_element'), - 'use_pager' => array('items_per_page', 'offset', 'use_pager', 'pager_element'), + 'pager' => array('pager'), 'use_more' => array('use_more', 'use_more_always', 'use_more_text'), 'link_display' => array('link_display'), 'distinct' => array('distinct'), @@ -255,8 +253,7 @@ class views_plugin_display extends views_plugin { 'use_ajax' => TRUE, 'items_per_page' => TRUE, 'offset' => TRUE, - 'use_pager' => TRUE, - 'pager_element' => TRUE, + 'pager' => TRUE, 'use_more' => TRUE, 'use_more_always' => TRUE, 'use_more_text' => TRUE, @@ -309,6 +306,11 @@ class views_plugin_display extends views_plugin { 'type' => array('default' => 'none'), ), ), + 'pager' => array( + 'contains' => array( + 'type' => array('default' => 'none'), + ), + ), 'title' => array( 'default' => '', 'translatable' => TRUE, @@ -349,12 +351,6 @@ class views_plugin_display extends views_plugin { 'offset' => array( 'default' => 0, ), - 'use_pager' => array( - 'default' => FALSE, - ), - 'pager_element' => array( - 'default' => 0, - ), 'use_more' => array( 'default' => FALSE, ), @@ -569,6 +565,22 @@ class views_plugin_display extends views_plugin { } /** + * Get the pager plugin + */ + function get_pager_plugin($name = NULL) { + if (!$name) { + $pager = $this->get_option('pager'); + $name = $pager['type']; + } + + $plugin = views_get_plugin('pager', $name); + if ($plugin) { + $plugin->init($this->view, $this->display); + return $plugin; + } + } + + /** * Get the handler object for a single handler. */ function &get_handler($type, $id) { @@ -748,10 +760,19 @@ class views_plugin_display extends views_plugin { } if (!empty($this->definition['use pager'])) { - $options['use_pager'] = array( + + $pager_plugin = $this->get_pager_plugin(); + if (!$pager_plugin) { + // default to the no access control plugin. + $pager_plugin = views_get_plugin('pager', 'none'); + } + + $pager_str = $pager_plugin->summary_title(); + + $options['pager'] = array( 'category' => 'basic', 'title' => t('Use pager'), - 'value' => $this->get_option('use_pager') ? ($this->get_option('use_pager') === 'mini' ? t('Mini') : t('Yes')) : t('No'), + 'value' => $pager_str, 'desc' => t("Change this display's pager setting."), ); } @@ -828,6 +849,14 @@ class views_plugin_display extends views_plugin { $options['cache']['links']['cache_options'] = t('Change settings for this caching type.'); } + if (!empty($access_plugin->definition['uses options'])) { + $options['access']['links']['access_options'] = t('Change settings for this access type.'); + } + + if (!empty($pager_plugin->definition['uses options'])) { + $options['pager']['links']['pager_options'] = t('Change settings for this pager type.'); + } + if ($this->uses_link_display()) { // Only show the 'link display' if there is more than one option. $count = 0; @@ -964,19 +993,47 @@ class views_plugin_display extends views_plugin { '#default_value' => $this->get_option('use_ajax') ? 1 : 0, ); break; - case 'use_pager': + case 'pager': $form['#title'] .= t('Use a pager for this view'); - $form['use_pager'] = array( - '#type' => 'radios', - '#options' => array(TRUE => t('Full pager'), 'mini' => t('Mini pager'), 0 => t('No')), - '#default_value' => $this->get_option('use_pager'), + $form['pager'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#tree' => TRUE, ); - $form['pager_element'] = array( - '#type' => 'textfield', - '#title' => t('Pager element'), - '#description' => t("Unless you're experiencing problems with pagers related to this view, you should leave this at 0. If using multiple pagers on one page you may need to set this number to a higher value so as not to conflict within the ?page= array. Large values will add a lot of commas to your URLs, so avoid if possible."), - '#default_value' => intval($this->get_option('pager_element')), + + $pager = $this->get_option('pager'); + $form['pager']['type'] = array( + '#type' => 'radios', + '#options' => views_fetch_plugin_names('pager'), + '#default_value' => $pager['type'], ); + + $pager_plugin = views_fetch_plugin_data('pager', $pager['type']); + if (!empty($pager_plugin['uses options'])) { + $form['markup'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#value' => t('You may also adjust the !settings for the currently selected access restriction by clicking on the icon.', array('!settings' => $this->option_link(t('settings'), 'access_options'))), + ); + } + + break; + case 'pager_options': + $pager = $this->get_option('pager'); + $plugin = $this->get_pager_plugin(); + $form['#title'] .= t('Pager options'); + if ($plugin) { + $form['#help_topic'] = $plugin->definition['help topic']; + + $form['pager_options'] = array( + '#tree' => TRUE, + ); + $form['pager_options']['type'] = array( + '#type' => 'value', + '#value' => $pager['type'], + ); + $plugin->options_form($form['pager_options'], $form_state); + } break; case 'items_per_page': $form['#title'] .= $this->use_pager() ? t('Items per page') : t('Items to display'); @@ -1636,12 +1693,26 @@ class views_plugin_display extends views_plugin { case 'link_display': $this->set_option($section, $form_state['values'][$section]); break; - case 'use_ajax': - $this->set_option($section, (bool)$form_state['values'][$section]); + case 'pager': + $pager = $this->get_option('pager'); + if ($pager['type'] != $form_state['values']['pager']['type']) { + $plugin = views_get_plugin('pager', $form_state['values']['pager']['type']); + if ($plugin) { + $pager = array('type' => $form_state['values']['pager']['type']); + $this->set_option('pager', $pager); + if (!empty($plugin->definition['uses options'])) { + views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('pager_options')); + } + } + } + break; - case 'use_pager': - $this->set_option($section, $form_state['values'][$section]); - $this->set_option('pager_element', intval($form_state['values']['pager_element'])); + case 'pager_options': + $plugin = views_get_plugin('pager', $form_state['values'][$section]['type']); + if ($plugin) { + $plugin->options_submit($form['pager_options'], $form_state); + $this->set_option('pager', $form_state['values'][$section]); + } break; case 'items_per_page': $this->set_option($section, intval($form_state['values'][$section])); diff --git plugins/views_plugin_pager.inc plugins/views_plugin_pager.inc new file mode 100644 index 0000000..5db026e --- /dev/null +++ plugins/views_plugin_pager.inc @@ -0,0 +1,67 @@ +view = &$view; + $this->display = &$display; + $this->options = array(); + + if (is_object($display->handler)) { + // Note: The below is read only. + $this->options = $display->handler->get_option('pager'); + } + } + + /** + * Define the default options when this is a new pager plugin + */ + function option_definition() { + $options = parent::option_definition(); + + return $options; + } + + /** + * Provide the default form for setting options. + */ + function options_form(&$form, &$form_state) { } + + /** + * Provide the default form form for validating options + */ + function options_validate(&$form, &$form_state) { } + + /** + * Provide the default form form for submitting options + */ + function options_submit(&$form, &$form_state) { } + + /** + * Return a string to display as the clickable title for the + * pager plugin. + */ + function summary_title() { + return t('Unknown'); + } + + function use_pager() { + return TRUE; + } + + function render() { } +} diff --git plugins/views_plugin_pager_full.inc plugins/views_plugin_pager_full.inc new file mode 100644 index 0000000..8c035cb --- /dev/null +++ plugins/views_plugin_pager_full.inc @@ -0,0 +1,35 @@ + 'textfield', + '#title' => t('Pager element'), + '#description' => t("Unless you're experiencing problems with pagers related to this view, you should leave this at 0. If using multiple pagers on one page you may need to set this number to a higher value so as not to conflict within the ?page= array. Large values will add a lot of commas to your URLs, so avoid if possible."), + '#default_value' => 20, + ); + + $form['pager_pages'] = array( + '#type' => 'textfield', + '#title' => t('Pages for pager'), + '#description' => t('How many pages display in pager.'), + '#default_value' => 0, + ); + } + + /** + * Return a string to display as the clickable title for the + * pager plugin. + */ + function summary_title() { + return t('Full Pager'); + } +} diff --git plugins/views_plugin_pager_mini.inc plugins/views_plugin_pager_mini.inc new file mode 100644 index 0000000..542595b --- /dev/null +++ plugins/views_plugin_pager_mini.inc @@ -0,0 +1,18 @@ +