[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/views/handlers/ -> views_handler_field_prerender_list.inc (source)

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


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7