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