source: sipes/modules_contrib/views/handlers/views_handler_field_prerender_list.inc @ 65dadeb

stableversion-3.0
Last change on this file since 65dadeb 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: 3.7 KB
Línea 
1<?php
2
3/**
4 * Field handler to provide a list of items.
5 *
6 * The items are expected to be loaded by a child object during pre_render,
7 * and 'my field' is expected to be the pointer to the items in the list.
8 *
9 * Items to render should be in a list in $this->items
10 *
11 * @ingroup views_field_handlers
12 */
13class views_handler_field_prerender_list extends views_handler_field {
14  /**
15   * Stores all items which are used to render the items.
16   * It should be keyed first by the id of the base table, for example nid.
17   * The second key is the id of the thing which is displayed multiple times
18   * per row, for example the tid.
19   *
20   * @var array
21   */
22  var $items = array();
23
24  function option_definition() {
25    $options = parent::option_definition();
26
27    $options['type'] = array('default' => 'separator');
28    $options['separator'] = array('default' => ', ');
29
30    return $options;
31  }
32
33  function options_form(&$form, &$form_state) {
34    parent::options_form($form, $form_state);
35    $form['type'] = array(
36      '#type' => 'radios',
37      '#title' => t('Display type'),
38      '#options' => array(
39        'ul' => t('Unordered list'),
40        'ol' => t('Ordered list'),
41        'separator' => t('Simple separator'),
42      ),
43      '#default_value' => $this->options['type'],
44    );
45
46    $form['separator'] = array(
47      '#type' => 'textfield',
48      '#title' => t('Separator'),
49      '#default_value' => $this->options['separator'],
50      '#process' => array('views_process_dependency'),
51      '#dependency' => array('radio:options[type]' => array('separator')),
52    );
53  }
54
55  /**
56   * Render the field.
57   *
58   * This function is deprecated, but left in for older systems that have not
59   * yet or won't update their prerender list fields. If a render_item method
60   * exists, this will not get used by advanced_render.
61   */
62  function render($values) {
63    $field = $this->get_value($values);
64    if (!empty($this->items[$field])) {
65      if ($this->options['type'] == 'separator') {
66        return implode($this->sanitize_value($this->options['separator']), $this->items[$field]);
67      }
68      else {
69        return theme('item_list', $this->items[$field], NULL, $this->options['type']);
70      }
71    }
72  }
73
74  /**
75   * Render all items in this field together.
76   *
77   * When using advanced render, each possible item in the list is rendered
78   * individually. Then the items are all pasted together.
79   */
80  function render_items($items) {
81    if (!empty($items)) {
82      if ($this->options['type'] == 'separator') {
83        return implode($this->sanitize_value($this->options['separator']), $items);
84      }
85      else {
86        return theme('item_list', $items, NULL, $this->options['type']);
87      }
88    }
89  }
90
91  /**
92   * Return an array of items for the field.
93   *
94   * Items should be stored in the result array, if possible, as an array
95   * with 'value' as the actual displayable value of the item, plus
96   * any items that might be found in the 'alter' options array for
97   * creating links, such as 'path', 'fragment', 'query' etc, such a thing
98   * is to be made. Additionally, items that might be turned into tokens
99   * should also be in this array.
100   */
101  function get_items($values) {
102    $field = $this->get_value($values);
103    if (!empty($this->items[$field])) {
104      return $this->items[$field];
105    }
106
107    return array();
108  }
109
110  /**
111   * Determine if advanced rendering is allowed.
112   *
113   * By default, advanced rendering will NOT be allowed if the class
114   * inheriting from this does not implement a 'render_items' method.
115   */
116  function allow_advanced_render() {
117    // Note that the advanced render bits also use the presence of
118    // this method to determine if it needs to render items as a list.
119    return method_exists($this, 'render_item');
120  }
121}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.