source: sipes/modules_contrib/views/plugins/views_plugin_style_jump_menu.inc

stableversion-3.0
Last change on this file was 59029b2, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se actualizo la version del modulo views

  • Propiedad mode establecida a 100644
File size: 5.5 KB
Línea 
1<?php
2/**
3 * @file
4 * Contains the table style plugin.
5 */
6
7/**
8 * Style plugin to render each item as a row in a table.
9 *
10 * @ingroup views_style_plugins
11 */
12class views_plugin_style_jump_menu extends views_plugin_style {
13  function option_definition() {
14    $options = parent::option_definition();
15
16    $options['hide'] = array('default' => FALSE);
17    $options['path'] = array('default' => '');
18    $options['text'] = array('default' => 'Go', 'translatable' => TRUE);
19    $options['choose'] = array('default' => '- Choose -', 'translatable' => TRUE);
20    $options['default_value'] = array('default' => FALSE);
21
22    return $options;
23  }
24
25  /**
26   * Render the given style.
27   */
28  function options_form(&$form, &$form_state) {
29    parent::options_form($form, $form_state);
30    $handlers = $this->display->handler->get_handlers('field');
31    if (empty($handlers)) {
32      $form['error_markup'] = array(
33        '#value' => t('You need at least one field before you can configure your jump menu settings'),
34        '#prefix' => '<div class="error form-item description">',
35        '#suffix' => '</div>',
36      );
37      return;
38    }
39
40    $form['markup'] = array(
41      '#value' => 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.'),
42      '#prefix' => '<div class="form-item description">',
43      '#suffix' => '</div>',
44    );
45
46    foreach ($handlers as $id => $handler) {
47      $options[$id] = $handler->ui_name();
48    }
49
50    $form['path'] = array(
51      '#type' => 'select',
52      '#title' => t('Path field'),
53      '#options' => $options,
54      '#default_value' => $this->options['path'],
55    );
56
57    $form['hide'] = array(
58      '#type' => 'checkbox',
59      '#title' => t('Hide the "Go" button'),
60      '#default_value' => !empty($this->options['hide']),
61      '#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.'),
62    );
63
64    $form['text'] = array(
65      '#type' => 'textfield',
66      '#title' => t('Button text'),
67      '#default_value' => $this->options['text'],
68    );
69
70    $form['choose'] = array(
71      '#type' => 'textfield',
72      '#title' => t('Choose text'),
73      '#default_value' => $this->options['choose'],
74      '#description' => t('The text that will appear as the selected option in the jump menu.'),
75    );
76
77    $form['default_value'] = array(
78      '#type' => 'checkbox',
79      '#title' => t('Select the current argument'),
80      '#default_value' => !empty($this->options['default_value']),
81      '#description' => t('If checked, the current path will be displayed as the default option in the jump menu, if applicable.'),
82    );
83  }
84
85  /**
86   * Render the display in this style.
87   *
88   * This is overridden so that we can render our grouping specially.
89   */
90  function render() {
91    $sets = $this->render_grouping($this->view->result, $this->options['grouping']);
92
93    // Turn this all into an $options array for the jump menu.
94    $this->view->row_index = 0;
95    $options = array();
96    $paths = array();
97
98    foreach ($sets as $title => $records) {
99      foreach ($records as $row_index => $row) {
100        $this->view->row_index = $row_index;
101        $path = html_entity_decode(strip_tags($this->get_field($this->view->row_index, $this->options['path'])), ENT_QUOTES);
102        // Putting a '/' in front messes up url() so let's take that out
103        // so users don't shoot themselves in the foot.
104        if (strpos($path, '/') === 0) {
105          $path = substr($path, 1);
106        }
107
108        // use parse_url() to preserve query and fragment in case the user
109        // wants to do fun tricks.
110        $url = parse_url($path);
111        $url_options = array();
112        if (isset($url['query'])) {
113          $path = strtr($path, array('?' . $url['query'] => ''));
114          $url_options['query'] = $url['query'];
115        }
116        if (isset($url['fragment'])) {
117          $path = strtr($path, array('#' . $url['fragment'] => ''));
118          $url_options['fragment'] = $url['fragment'];
119        }
120
121        $path = url($path, $url_options);
122        $field = html_entity_decode(strip_tags($this->row_plugin->render($row)), ENT_QUOTES);
123        $key = md5($path . $field) . "::" . $path;
124        if ($title) {
125          $options[$title][$key] = $field;
126        }
127        else {
128          $options[$key] = $field;
129        }
130        $paths[$path] = $key;
131        $this->view->row_index++;
132      }
133    }
134    unset($this->view->row_index);
135
136    $default_value = '';
137    if ($this->options['default_value']) {
138      $lookup_options = array();
139      // We need to check if the path is absolute
140      // or else language is not taken in account.
141      if ($this->view->display[$this->view->current_display]->display_options['fields'][$this->options['path']]['absolute']) {
142        $lookup_options['absolute'] = TRUE;
143      }
144      $lookup_url = url($_GET['q'], $lookup_options);
145      if (!empty($paths[$lookup_url])) {
146        $default_value = $paths[$lookup_url];
147      }
148    }
149
150    ctools_include('jump-menu');
151    $settings = array(
152      'hide' => $this->options['hide'],
153      'button' => $this->options['text'],
154      'choose' => $this->options['choose'],
155      'default_value' => $default_value,
156    );
157
158    return drupal_get_form('ctools_jump_menu', $options, $settings);
159  }
160
161  function render_set($title, $records) {
162    $options = array();
163    $fields = $this->rendered_fields;
164  }
165}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.