Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views / plugins / views_plugin_style_summary_jump_menu.inc @ 8be7bf84

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_plugin_style_summary_jump_menu.
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

    
15
  /**
16
   * {@inheritdoc}
17
   */
18
  public function option_definition() {
19
    $options = parent::option_definition();
20

    
21
    $options['base_path'] = array('default' => '');
22
    $options['count'] = array('default' => TRUE, 'bool' => TRUE);
23
    $options['hide'] = array('default' => FALSE, 'bool' => TRUE);
24
    $options['text'] = array('default' => 'Go', 'translatable' => TRUE);
25
    $options['label'] = array('default' => '', 'translatable' => TRUE);
26
    $options['choose'] = array('default' => '- Choose -', 'translatable' => TRUE);
27
    $options['inline'] = array('default' => TRUE, 'bool' => TRUE);
28
    $options['default_value'] = array('default' => FALSE, 'bool' => TRUE);
29

    
30
    return $options;
31
  }
32

    
33
  /**
34
   * {@inheritdoc}
35
   */
36
  public function query() {
37
    // Copy the offset option.
38
    $pager = array(
39
      'type' => 'none',
40
      'options' => $this->display->handler->options['pager']['options'],
41
    );
42
    $this->display->handler->set_option('pager', $pager);
43
  }
44

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

    
65
    $form['hide'] = array(
66
      '#type' => 'checkbox',
67
      '#title' => t('Hide the "Go" button'),
68
      '#default_value' => !empty($this->options['hide']),
69
      '#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.'),
70
    );
71

    
72
    $form['text'] = array(
73
      '#type' => 'textfield',
74
      '#title' => t('Button text'),
75
      '#default_value' => $this->options['text'],
76
    );
77

    
78
    $form['label'] = array(
79
      '#type' => 'textfield',
80
      '#title' => t('Selector label'),
81
      '#default_value' => $this->options['label'],
82
      '#description' => t('The text that will appear as the the label of the selector element. If blank no label tag will be used.'),
83
    );
84

    
85
    $form['choose'] = array(
86
      '#type' => 'textfield',
87
      '#title' => t('Choose text'),
88
      '#default_value' => $this->options['choose'],
89
      '#description' => t('The text that will appear as the selected option in the jump menu.'),
90
    );
91

    
92
    $form['inline'] = array(
93
      '#type' => 'checkbox',
94
      '#title' => t('Set this field to display inline'),
95
      '#default_value' => !empty($this->options['inline']),
96
    );
97

    
98
    $form['default_value'] = array(
99
      '#type' => 'checkbox',
100
      '#title' => t('Select the current contextual filter value'),
101
      '#default_value' => !empty($this->options['default_value']),
102
      '#description' => t('If checked, the current contextual filter value will be displayed as the default option in the jump menu, if applicable.'),
103
    );
104
  }
105

    
106
  /**
107
   * {@inheritdoc}
108
   */
109
  public function render() {
110
    $argument = $this->view->argument[$this->view->build_info['summary_level']];
111

    
112
    $url_options = array();
113

    
114
    if (!empty($this->view->exposed_raw_input)) {
115
      $url_options['query'] = $this->view->exposed_raw_input;
116
    }
117

    
118
    $options = array();
119
    $default_value = '';
120
    $row_args = array();
121
    foreach ($this->view->result as $id => $row) {
122
      $row_args[$id] = $argument->summary_argument($row);
123
    }
124
    $argument->process_summary_arguments($row_args);
125

    
126
    foreach ($this->view->result as $id => $row) {
127
      $args = $this->view->args;
128
      $args[$argument->position] = $row_args[$id];
129
      $base_path = NULL;
130
      if (!empty($argument->options['summary_options']['base_path'])) {
131
        $base_path = $argument->options['summary_options']['base_path'];
132
      }
133
      $path = url($this->view->get_url($args, $base_path), $url_options);
134
      $summary_value = strip_tags($argument->summary_name($row));
135
      $key = md5($path . $summary_value) . "::" . $path;
136

    
137
      $options[$key] = $summary_value;
138
      if (!empty($this->options['count'])) {
139
        $options[$key] .= ' (' . intval($row->{$argument->count_alias}) . ')';
140
      }
141
      if ($this->options['default_value'] && $_GET['q'] == $this->view->get_url($args)) {
142
        $default_value = $key;
143
      }
144
    }
145

    
146
    ctools_include('jump-menu');
147
    $settings = array(
148
      'hide' => $this->options['hide'],
149
      'button' => $this->options['text'],
150
      'title' => $this->options['label'],
151
      'choose' => $this->options['choose'],
152
      'inline' => $this->options['inline'],
153
      'default_value' => $default_value,
154
    );
155

    
156
    $form = drupal_get_form('ctools_jump_menu', $options, $settings);
157
    return drupal_render($form);
158
  }
159

    
160
}