Projet

Général

Profil

Paste
Télécharger (5,09 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / plugins / views_plugin_style_summary_jump_menu.inc @ 7547bb19

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains the default summary style plugin, which displays items in an HTML list.
6
 */
7

    
8
/**
9
 * The default style plugin for summaries.
10
 *
11
 * @ingroup views_style_plugins
12
 */
13
class views_plugin_style_summary_jump_menu extends views_plugin_style {
14
  function option_definition() {
15
    $options = parent::option_definition();
16

    
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

    
26
    return $options;
27
  }
28

    
29
  function query() {
30
    // Copy the offset option.
31
    $pager = array(
32
      'type' => 'none',
33
      'options' => $this->display->handler->options['pager']['options'],
34
    );
35
    $this->display->handler->set_option('pager', $pager);
36
  }
37

    
38
  function options_form(&$form, &$form_state) {
39
    $form['base_path'] = array(
40
      '#type' => 'textfield',
41
      '#title' => t('Base path'),
42
      '#default_value' => $this->options['base_path'],
43
      '#description' => t('Define the base path for links in this summary
44
        view, i.e. http://example.com/<strong>your_view_path/archive</strong>.
45
        Do not include beginning and ending forward slash. If this value
46
        is empty, views will use the first path found as the base path,
47
        in page displays, or / if no path could be found.'),
48
    );
49
    $form['count'] = array(
50
      '#type' => 'checkbox',
51
      '#default_value' => !empty($this->options['count']),
52
      '#title' => t('Display record count with link'),
53
    );
54

    
55
    $form['hide'] = array(
56
      '#type' => 'checkbox',
57
      '#title' => t('Hide the "Go" button'),
58
      '#default_value' => !empty($this->options['hide']),
59
      '#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.'),
60
    );
61

    
62
    $form['text'] = array(
63
      '#type' => 'textfield',
64
      '#title' => t('Button text'),
65
      '#default_value' => $this->options['text'],
66
    );
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

    
75
    $form['choose'] = array(
76
      '#type' => 'textfield',
77
      '#title' => t('Choose text'),
78
      '#default_value' => $this->options['choose'],
79
      '#description' => t('The text that will appear as the selected option in the jump menu.'),
80
    );
81

    
82
    $form['inline'] = array(
83
      '#type' => 'checkbox',
84
      '#title' => t('Set this field to display inline'),
85
      '#default_value' => !empty($this->options['inline']),
86
    );
87

    
88
    $form['default_value'] = array(
89
      '#type' => 'checkbox',
90
      '#title' => t('Select the current contextual filter value'),
91
      '#default_value' => !empty($this->options['default_value']),
92
      '#description' => t('If checked, the current contextual filter value will be displayed as the default option in the jump menu, if applicable.'),
93
    );
94
  }
95

    
96
  function render() {
97
    $argument = $this->view->argument[$this->view->build_info['summary_level']];
98

    
99
    $url_options = array();
100

    
101
    if (!empty($this->view->exposed_raw_input)) {
102
      $url_options['query'] = $this->view->exposed_raw_input;
103
    }
104

    
105
    $options = array();
106
    $default_value = '';
107
    $row_args = array();
108
    foreach ($this->view->result as $id => $row) {
109
      $row_args[$id] = $argument->summary_argument($row);
110
    }
111
    $argument->process_summary_arguments($row_args);
112

    
113
    foreach ($this->view->result as $id => $row) {
114
      $args = $this->view->args;
115
      $args[$argument->position] = $row_args[$id];
116
      $base_path = NULL;
117
      if (!empty($argument->options['summary_options']['base_path'])) {
118
        $base_path = $argument->options['summary_options']['base_path'];
119
      }
120
      $path = url($this->view->get_url($args, $base_path), $url_options);
121
      $summary_value = strip_tags($argument->summary_name($row));
122
      $key = md5($path . $summary_value) . "::" . $path;
123

    
124
      $options[$key] = $summary_value;
125
      if (!empty($this->options['count'])) {
126
        $options[$key] .= ' (' . intval($row->{$argument->count_alias}) . ')';
127
      }
128
      if ($this->options['default_value'] && $_GET['q'] == $this->view->get_url($args)) {
129
        $default_value = $key;
130
      }
131
    }
132

    
133
    ctools_include('jump-menu');
134
    $settings = array(
135
      'hide' => $this->options['hide'],
136
      'button' => $this->options['text'],
137
      'title' => $this->options['label'],
138
      'choose' => $this->options['choose'],
139
      'inline' => $this->options['inline'],
140
      'default_value' => $default_value,
141
    );
142

    
143
    $form = drupal_get_form('ctools_jump_menu', $options, $settings);
144
    return drupal_render($form);
145
  }
146
}