views_plugin_style_summary_jump_menu.inc

  1. 3.x plugins/views_plugin_style_summary_jump_menu.inc
  2. 2.x plugins/views_plugin_style_summary_jump_menu.inc

Contains the default summary style plugin, which displays items in an HTML list.

File

plugins/views_plugin_style_summary_jump_menu.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Contains the default summary style plugin, which displays items in an HTML list.
  5. */
  6. /**
  7. * The default style plugin for summaries.
  8. *
  9. * @ingroup views_style_plugins
  10. */
  11. class views_plugin_style_summary_jump_menu extends views_plugin_style {
  12. function option_definition() {
  13. $options = parent::option_definition();
  14. $options['base_path'] = array('default' => '');
  15. $options['count'] = array('default' => TRUE);
  16. $options['hide'] = array('default' => FALSE);
  17. $options['text'] = array('default' => 'Go', 'translatable' => TRUE);
  18. $options['choose'] = array('default' => '- Choose -', 'translatable' => TRUE);
  19. $options['default_value'] = array('default' => FALSE);
  20. return $options;
  21. }
  22. function query() {
  23. // We can't have an offset without a limit, so provide a very large limit instead.
  24. if (!empty($this->display->handler->options['offset'])) {
  25. $this->view->set_items_per_page(999999);
  26. }
  27. else {
  28. $this->view->set_items_per_page(0);
  29. $this->view->set_use_pager(0);
  30. }
  31. }
  32. function options_form(&$form, &$form_state) {
  33. parent::options_form($form, $form_state);
  34. $form['base_path'] = array(
  35. '#type' => 'textfield',
  36. '#title' => t('Base path'),
  37. '#default_value' => $this->options['base_path'],
  38. '#description' => t('Define the base path for links in this summary
  39. view, i.e. http://example.com/<strong>your_view_path/archive</strong>.
  40. Do not include beginning and ending forward slash. If this value
  41. is empty, views will use the first path found as the base path,
  42. in page displays, or / if no path could be found.'),
  43. );
  44. $form['count'] = array(
  45. '#type' => 'checkbox',
  46. '#default_value' => !empty($this->options['count']),
  47. '#title' => t('Display record count with link'),
  48. );
  49. $form['hide'] = array(
  50. '#type' => 'checkbox',
  51. '#title' => t('Hide the "Go" button.'),
  52. '#default_value' => !empty($this->options['hide']),
  53. '#description' => t('If hidden, this button will only be hidden for users with javascript and the page will automatically jump when the select is changed.'),
  54. );
  55. $form['text'] = array(
  56. '#type' => 'textfield',
  57. '#title' => t('Button text'),
  58. '#default_value' => $this->options['text'],
  59. );
  60. $form['choose'] = array(
  61. '#type' => 'textfield',
  62. '#title' => t('Choose text'),
  63. '#default_value' => $this->options['choose'],
  64. '#description' => t('The text that will appear as the selected option in the jump menu.'),
  65. );
  66. $form['default_value'] = array(
  67. '#type' => 'checkbox',
  68. '#title' => t('Select the current argument.'),
  69. '#default_value' => !empty($this->options['default_value']),
  70. '#description' => t('If checked, the current argument setting will be displayed as the default option in the jump menu, if applicable.'),
  71. );
  72. }
  73. function render() {
  74. $argument = $this->view->argument[$this->view->build_info['summary_level']];
  75. $url_options = array();
  76. if (!empty($this->view->exposed_raw_input)) {
  77. $url_options['query'] = $this->view->exposed_raw_input;
  78. }
  79. $options = array();
  80. $default_value = '';
  81. foreach ($this->view->result as $id => $row) {
  82. $args = $this->view->args;
  83. $args[$argument->position] = $argument->summary_argument($row);
  84. $base_path = NULL;
  85. if (!empty($argument->options['style_options']['base_path'])) {
  86. $base_path = $argument->options['style_options']['base_path'];
  87. }
  88. $path = url($this->view->get_url($args, $base_path), $url_options);
  89. $options[$path] = strip_tags($argument->summary_name($row));
  90. if (!empty($this->options['count'])) {
  91. $options[$path] .= ' (' . intval($row->{$argument->count_alias}) . ')';
  92. }
  93. if ($this->options['default_value'] && $_GET['q'] == $this->view->get_url($args)) {
  94. $default_value = $path;
  95. }
  96. }
  97. ctools_include('jump-menu');
  98. $settings = array(
  99. 'hide' => $this->options['hide'],
  100. 'button' => $this->options['text'],
  101. 'choose' => $this->options['choose'],
  102. 'default_value' => $default_value,
  103. );
  104. return drupal_get_form('ctools_jump_menu', $options, $settings);
  105. }
  106. }