views_plugin_style_summary_jump_menu.inc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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, 'bool' => TRUE);
  16. $options['hide'] = array('default' => FALSE, 'bool' => TRUE);
  17. $options['text'] = array('default' => 'Go', 'translatable' => TRUE);
  18. $options['label'] = array('default' => '', 'translatable' => TRUE);
  19. $options['choose'] = array('default' => '- Choose -', 'translatable' => TRUE);
  20. $options['default_value'] = array('default' => FALSE, 'bool' => TRUE);
  21. return $options;
  22. }
  23. function query() {
  24. // Copy the offset option.
  25. $pager = array(
  26. 'type' => 'none',
  27. 'options' => $this->display->handler->options['pager']['options'],
  28. );
  29. $this->display->handler->set_option('pager', $pager);
  30. }
  31. function options_form(&$form, &$form_state) {
  32. $form['base_path'] = array(
  33. '#type' => 'textfield',
  34. '#title' => t('Base path'),
  35. '#default_value' => $this->options['base_path'],
  36. '#description' => t('Define the base path for links in this summary
  37. view, i.e. http://example.com/<strong>your_view_path/archive</strong>.
  38. Do not include beginning and ending forward slash. If this value
  39. is empty, views will use the first path found as the base path,
  40. in page displays, or / if no path could be found.'),
  41. );
  42. $form['count'] = array(
  43. '#type' => 'checkbox',
  44. '#default_value' => !empty($this->options['count']),
  45. '#title' => t('Display record count with link'),
  46. );
  47. $form['hide'] = array(
  48. '#type' => 'checkbox',
  49. '#title' => t('Hide the "Go" button'),
  50. '#default_value' => !empty($this->options['hide']),
  51. '#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.'),
  52. );
  53. $form['text'] = array(
  54. '#type' => 'textfield',
  55. '#title' => t('Button text'),
  56. '#default_value' => $this->options['text'],
  57. );
  58. $form['label'] = array(
  59. '#type' => 'textfield',
  60. '#title' => t('Selector label'),
  61. '#default_value' => $this->options['label'],
  62. '#description' => t('The text that will appear as the the label of the selector element. If blank no label tag will be used.'),
  63. );
  64. $form['choose'] = array(
  65. '#type' => 'textfield',
  66. '#title' => t('Choose text'),
  67. '#default_value' => $this->options['choose'],
  68. '#description' => t('The text that will appear as the selected option in the jump menu.'),
  69. );
  70. $form['default_value'] = array(
  71. '#type' => 'checkbox',
  72. '#title' => t('Select the current contextual filter value'),
  73. '#default_value' => !empty($this->options['default_value']),
  74. '#description' => t('If checked, the current contextual filter value will be displayed as the default option in the jump menu, if applicable.'),
  75. );
  76. }
  77. function render() {
  78. $argument = $this->view->argument[$this->view->build_info['summary_level']];
  79. $url_options = array();
  80. if (!empty($this->view->exposed_raw_input)) {
  81. $url_options['query'] = $this->view->exposed_raw_input;
  82. }
  83. $options = array();
  84. $default_value = '';
  85. $row_args = array();
  86. foreach ($this->view->result as $id => $row) {
  87. $row_args[$id] = $argument->summary_argument($row);
  88. }
  89. $argument->process_summary_arguments($row_args);
  90. foreach ($this->view->result as $id => $row) {
  91. $args = $this->view->args;
  92. $args[$argument->position] = $row_args[$id];
  93. $base_path = NULL;
  94. if (!empty($argument->options['summary_options']['base_path'])) {
  95. $base_path = $argument->options['summary_options']['base_path'];
  96. }
  97. $path = url($this->view->get_url($args, $base_path), $url_options);
  98. $summary_value = strip_tags($argument->summary_name($row));
  99. $key = md5($path . $summary_value) . "::" . $path;
  100. $options[$key] = $summary_value;
  101. if (!empty($this->options['count'])) {
  102. $options[$key] .= ' (' . intval($row->{$argument->count_alias}) . ')';
  103. }
  104. if ($this->options['default_value'] && $_GET['q'] == $this->view->get_url($args)) {
  105. $default_value = $key;
  106. }
  107. }
  108. ctools_include('jump-menu');
  109. $settings = array(
  110. 'hide' => $this->options['hide'],
  111. 'button' => $this->options['text'],
  112. 'title' => $this->options['label'],
  113. 'choose' => $this->options['choose'],
  114. 'default_value' => $default_value,
  115. );
  116. $form = drupal_get_form('ctools_jump_menu', $options, $settings);
  117. return drupal_render($form);
  118. }
  119. }