• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

modules/comment/views_handler_field_comment.inc

00001 <?php
00007 class views_handler_field_comment extends views_handler_field {
00011   function init(&$view, &$options) {
00012     parent::init($view, $options);
00013     if (!empty($this->options['link_to_comment'])) {
00014       $this->additional_fields['cid'] = 'cid';
00015       $this->additional_fields['nid'] = 'nid';
00016     }
00017   }
00018 
00019   function option_definition() {
00020     $options = parent::option_definition();
00021     $options['link_to_comment'] = array('default' => TRUE);
00022     $options['link_to_node'] = array('default' => FALSE);
00023 
00024     return $options;
00025   }
00026 
00030   function options_form(&$form, &$form_state) {
00031     $form['link_to_comment'] = array(
00032       '#title' => t('Link this field to its comment'),
00033       '#description' => t("Enable to override this field's links."),
00034       '#type' => 'checkbox',
00035       '#default_value' => $this->options['link_to_comment'],
00036     );
00037     $form['link_to_node'] = array(
00038       '#title' => t('Link field to the node if there is no comment.'),
00039       '#type' => 'checkbox',
00040       '#default_value' => $this->options['link_to_node'],
00041     );
00042     parent::options_form($form, $form_state);
00043   }
00044 
00045   function render_link($data, $values) {
00046     if (!empty($this->options['link_to_comment'])) {
00047       $this->options['alter']['make_link'] = TRUE;
00048       $nid = $this->get_value($values, 'nid');
00049       $cid = $this->get_value($values, 'cid');
00050       if (!empty($cid)) {
00051         $this->options['alter']['path'] = "comment/" . $cid;
00052         $this->options['alter']['fragment'] = "comment-" . $cid;
00053       }
00054       // If there is no comment link to the node.
00055       else if ($this->options['link_to_node']) {
00056         $this->options['alter']['path'] = "node/" . $nid;
00057       }
00058     }
00059 
00060     return $data;
00061   }
00062 
00063   function render($values) {
00064     $value = $this->get_value($values);
00065     return $this->render_link($this->sanitize_value($value), $values);
00066   }
00067 }

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1