Projet

Général

Profil

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

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

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains the table style plugin.
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
  function option_definition() {
15
    $options = parent::option_definition();
16

    
17
    $options['hide'] = array('default' => FALSE, 'bool' => TRUE);
18
    $options['path'] = array('default' => '');
19
    $options['text'] = array('default' => 'Go', 'translatable' => TRUE);
20
    $options['label'] = array('default' => '', 'translatable' => TRUE);
21
    $options['choose'] = array('default' => '- Choose -', 'translatable' => TRUE);
22
    $options['inline'] = array('default' => TRUE, 'bool' => TRUE);
23
    $options['default_value'] = array('default' => FALSE, 'bool' => TRUE);
24

    
25
    return $options;
26
  }
27

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

    
43
    $form['markup'] = array(
44
      '#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.'),
45
      '#prefix' => '<div class="form-item description">',
46
      '#suffix' => '</div>',
47
    );
48

    
49
    foreach ($handlers as $id => $handler) {
50
      $options[$id] = $handler->ui_name();
51
    }
52

    
53
    $form['path'] = array(
54
      '#type' => 'select',
55
      '#title' => t('Path field'),
56
      '#options' => $options,
57
      '#default_value' => $this->options['path'],
58
    );
59

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

    
67
    $form['text'] = array(
68
      '#type' => 'textfield',
69
      '#title' => t('Button text'),
70
      '#default_value' => $this->options['text'],
71
    );
72

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

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

    
87
    $form['inline'] = array(
88
      '#type' => 'checkbox',
89
      '#title' => t('Set this field to display inline'),
90
      '#default_value' => !empty($this->options['inline']),
91
    );
92

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

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

    
109
    // Turn this all into an $options array for the jump menu.
110
    $this->view->row_index = 0;
111
    $options = array();
112
    $paths = array();
113

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

    
125
        // use drupal_parse_url() to preserve query and fragment in case the user
126
        // wants to do fun tricks.
127
        $url_options = drupal_parse_url($path);
128

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

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

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

    
168
    $form = drupal_get_form('ctools_jump_menu', $options, $settings);
169
    return $form;
170
  }
171

    
172
  function render_set($title, $records) {
173
    $options = array();
174
    $fields = $this->rendered_fields;
175
  }
176
}