views_plugin_style_summary_jump_menu.inc 5.2 KB

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