views_plugin_style_summary.inc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_plugin_style_summary.
  5. */
  6. /**
  7. * The default style plugin for summaries.
  8. *
  9. * @ingroup views_style_plugins
  10. */
  11. class views_plugin_style_summary 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['override'] = array('default' => FALSE, 'bool' => TRUE);
  20. $options['items_per_page'] = array('default' => 25);
  21. return $options;
  22. }
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function query() {
  27. if (!empty($this->options['override'])) {
  28. $this->view->set_items_per_page(intval($this->options['items_per_page']));
  29. }
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function options_form(&$form, &$form_state) {
  35. $form['base_path'] = array(
  36. '#type' => 'textfield',
  37. '#title' => t('Base path'),
  38. '#default_value' => $this->options['base_path'],
  39. '#description' => t('Define the base path for links in this summary
  40. view, i.e. http://example.com/<strong>your_view_path/archive</strong>.
  41. Do not include beginning and ending forward slash. If this value
  42. is empty, views will use the first path found as the base path,
  43. in page displays, or / if no path could be found.'),
  44. );
  45. $form['count'] = array(
  46. '#type' => 'checkbox',
  47. '#default_value' => !empty($this->options['count']),
  48. '#title' => t('Display record count with link'),
  49. );
  50. $form['override'] = array(
  51. '#type' => 'checkbox',
  52. '#default_value' => !empty($this->options['override']),
  53. '#title' => t('Override number of items to display'),
  54. );
  55. $form['items_per_page'] = array(
  56. '#type' => 'textfield',
  57. '#title' => t('Items to display'),
  58. '#default_value' => $this->options['items_per_page'],
  59. '#dependency' => array(
  60. 'edit-options-summary-options-' . str_replace('_', '-', $this->definition['name']) . '-override' => array(1),
  61. ),
  62. );
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. public function render() {
  68. $rows = array();
  69. foreach ($this->view->result as $row) {
  70. // @todo Include separator as an option.
  71. $rows[] = $row;
  72. }
  73. return theme($this->theme_functions(), array(
  74. 'view' => $this->view,
  75. 'options' => $this->options,
  76. 'rows' => $rows,
  77. ));
  78. }
  79. }