[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/views/modules/comment/ -> views_handler_field_comment.inc (source)

   1  <?php
   2  /**
   3   * Field handler to allow linking to a comment
   4   */
   5  class views_handler_field_comment extends views_handler_field {
   6    /**
   7     * Override init function to provide generic option to link to comment.
   8     */
   9    function init(&$view, &$options) {
  10      parent::init($view, $options);
  11      if (!empty($this->options['link_to_comment'])) {
  12        $this->additional_fields['cid'] = 'cid';
  13        $this->additional_fields['nid'] = 'nid';
  14      }
  15    }
  16  
  17    function option_definition() {
  18      $options = parent::option_definition();
  19      $options['link_to_comment'] = array('default' => TRUE);
  20      return $options;
  21    }
  22  
  23    /**
  24     * Provide link-to-comment option
  25     */
  26    function options_form(&$form, &$form_state) {
  27      parent::options_form($form, $form_state);
  28      $form['link_to_comment'] = array(
  29        '#title' => t('Link this field to its comment'),
  30        '#description' => t('This will override any other link you have set.'),
  31        '#type' => 'checkbox',
  32        '#default_value' => $this->options['link_to_comment'],
  33      );
  34    }
  35  
  36    function render_link($data, $values) {
  37      if (!empty($this->options['link_to_comment']) && $data !== NULL && $data !== '') {
  38        $this->options['alter']['make_link'] = TRUE;
  39        $this->options['alter']['path'] = "node/". $values->{$this->aliases['nid']};
  40        $this->options['alter']['fragment'] = "comment-" . $values->{$this->aliases['cid']};
  41      }
  42  
  43      return $data;
  44    }
  45  
  46    function render($values) {
  47      return $this->render_link(check_plain($values->{$this->field_alias}), $values);
  48    }
  49  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7