Projet

Général

Profil

Paste
Télécharger (6,08 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / plugins / views_plugin_style_jump_menu.inc @ 5d12d676

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_plugin_style_jump_menu.
6
 */
7

    
8
/**
9
 * Style plugin to render each item as a row in a table.
10
 *
11
 * @ingroup views_style_plugins
12
 */
13
class views_plugin_style_jump_menu extends views_plugin_style {
14

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

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

    
29
    return $options;
30
  }
31

    
32
  /**
33
   * Render the given style.
34
   */
35
  public function options_form(&$form, &$form_state) {
36
    parent::options_form($form, $form_state);
37
    $handlers = $this->display->handler->get_handlers('field');
38
    if (empty($handlers)) {
39
      $form['error_markup'] = array(
40
        '#markup' => t('You need at least one field before you can configure your jump menu settings'),
41
        '#prefix' => '<div class="error messages">',
42
        '#suffix' => '</div>',
43
      );
44
      return;
45
    }
46

    
47
    $form['markup'] = array(
48
      '#markup' => t('To properly configure a jump menu, you must select one field that will represent the path to utilize. You should then set that field to exclude. All other displayed fields will be part of the menu. Please note that all HTML will be stripped from this output as select boxes cannot show HTML.'),
49
      '#prefix' => '<div class="form-item description">',
50
      '#suffix' => '</div>',
51
    );
52

    
53
    foreach ($handlers as $id => $handler) {
54
      $options[$id] = $handler->ui_name();
55
    }
56

    
57
    $form['path'] = array(
58
      '#type' => 'select',
59
      '#title' => t('Path field'),
60
      '#options' => $options,
61
      '#default_value' => $this->options['path'],
62
    );
63

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

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

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

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

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

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

    
105
  /**
106
   * Render the display in this style.
107
   *
108
   * This is overridden so that we can render our grouping specially.
109
   */
110
  public function render() {
111
    $sets = $this->render_grouping($this->view->result, $this->options['grouping']);
112

    
113
    // Turn this all into an $options array for the jump menu.
114
    $this->view->row_index = 0;
115
    $options = array();
116
    $paths = array();
117

    
118
    foreach ($sets as $title => $records) {
119
      foreach ($records as $row_index => $row) {
120
        $this->view->row_index = $row_index;
121
        $path = strip_tags(decode_entities($this->get_field($this->view->row_index, $this->options['path'])));
122
        // Putting a '/' in front messes up url() so let's take that out
123
        // so users don't shoot themselves in the foot.
124
        $base_path = base_path();
125
        if (strpos($path, $base_path) === 0) {
126
          $path = drupal_substr($path, drupal_strlen($base_path));
127
        }
128

    
129
        // Use drupal_parse_url() to preserve query and fragment in case the
130
        // user wants to do fun tricks.
131
        $url_options = drupal_parse_url($path);
132

    
133
        $path = url($url_options['path'], $url_options);
134
        $field = strip_tags(decode_entities($this->row_plugin->render($row)));
135
        $key = md5($path . $field) . "::" . $path;
136
        if ($title) {
137
          $options[$title][$key] = $field;
138
        }
139
        else {
140
          $options[$key] = $field;
141
        }
142
        $paths[$path] = $key;
143
        $this->view->row_index++;
144
      }
145
    }
146
    unset($this->view->row_index);
147

    
148
    $default_value = '';
149
    if ($this->options['default_value']) {
150
      $lookup_options = array();
151
      // We need to check if the path is absolute or else language is not taken
152
      // in account.
153
      if (!empty($this->view->display[$this->view->current_display]->display_options['fields'][$this->options['path']]['absolute'])) {
154
        $lookup_options['absolute'] = TRUE;
155
      }
156
      $lookup_url = url($_GET['q'], $lookup_options);
157
      if (!empty($paths[$lookup_url])) {
158
        $default_value = $paths[$lookup_url];
159
      }
160
    }
161

    
162
    ctools_include('jump-menu');
163
    $settings = array(
164
      'hide' => $this->options['hide'],
165
      'button' => $this->options['text'],
166
      'title' => $this->options['label'],
167
      'choose' => $this->options['choose'],
168
      'inline' => $this->options['inline'],
169
      'default_value' => $default_value,
170
    );
171

    
172
    $form = drupal_get_form('ctools_jump_menu', $options, $settings);
173
    return $form;
174
  }
175

    
176
  /**
177
   *
178
   */
179
  public function render_set($title, $records) {
180
    $options = array();
181
    $fields = $this->rendered_fields;
182
  }
183

    
184
}