source: sipei/modules/views/plugins/views_plugin_style_jump_menu.inc

drupal-6.x
Last change on this file was ffa4103, checked in by Luis Peña <lpena@…>, 12 años ago

Cambiando el nombre de modulos a modules

  • Propiedad mode establecida a 100755
File size: 4.7 KB
Línea 
1<?php
2// $Id: views_plugin_style_jump_menu.inc,v 1.1.2.3 2010/03/13 00:06:20 merlinofchaos Exp $
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 */
13class 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);
18    $options['path'] = array('default' => '');
19    $options['text'] = array('default' => 'Go', 'translatable' => TRUE);
20    $options['choose'] = array('default' => '- Choose -', 'translatable' => TRUE);
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
78  /**
79   * Render the display in this style.
80   *
81   * This is overridden so that we can render our grouping specially.
82   */
83  function render() {
84    $result = $this->view->result;
85    // Group the rows according to the grouping field, if specified.
86    $fields = $this->render_fields($result);
87    $sets = array();
88    if ($this->options['grouping']) {
89      foreach ($result as $index => $row) {
90        $grouping = '';
91        // Group on the rendered version of the field, not the raw.  That way,
92        // we can control any special formatting of the grouping field through
93        // the admin or theme layer or anywhere else we'd like.
94        if (isset($this->view->field[$this->options['grouping']])) {
95          $grouping = strip_tags($this->get_field($index, $this->options['grouping']));
96          if ($this->view->field[$this->options['grouping']]->options['label']) {
97            $grouping = $this->view->field[$this->options['grouping']]->options['label'] . ': ' . $grouping;
98          }
99          $grouping = url($grouping);
100        }
101        $sets[$grouping][] = $row;
102      }
103    }
104    else {
105      // Create a single group with an empty grouping field.
106      $sets[''] = $result;
107    }
108
109    // Turn this all into an $options array for the jump menu.
110    $this->view->row_index = 0;
111    $options = array();
112    foreach ($sets as $title => $records) {
113      foreach ($records as $row) {
114        $path = strip_tags($this->get_field($this->view->row_index, $this->options['path']));
115        $field = strip_tags($this->row_plugin->render($row));;
116        if ($title) {
117          $options[$title][$path] = $field;
118        }
119        else {
120          $options[$path] = $field;
121        }
122        $this->view->row_index++;
123      }
124    }
125    unset($this->view->row_index);
126
127    ctools_include('jump-menu');
128    $settings = array(
129      'hide' => $this->options['hide'],
130      'button' => $this->options['text'],
131      'choose' => $this->options['choose'],
132    );
133
134    return drupal_get_form('ctools_jump_menu', $options, $settings);
135  }
136
137  function render_set($title, $records) {
138    $options = array();
139    $fields = $this->rendered_fields;
140  }
141}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.