00001 <?php
00007 class views_handler_field_comment_link extends views_handler_field_entity {
00008 function construct() {
00009 parent::construct();
00010 }
00011
00012 function option_definition() {
00013 $options = parent::option_definition();
00014 $options['text'] = array('default' => '', 'translatable' => TRUE);
00015 $options['link_to_node'] = array('default' => FALSE);
00016 return $options;
00017 }
00018
00019 function options_form(&$form, &$form_state) {
00020 $form['text'] = array(
00021 '#type' => 'textfield',
00022 '#title' => t('Text to display'),
00023 '#default_value' => $this->options['text'],
00024 );
00025 $form['link_to_node'] = array(
00026 '#title' => t('Link field to the node if there is no comment.'),
00027 '#type' => 'checkbox',
00028 '#default_value' => $this->options['link_to_node'],
00029 );
00030 parent::options_form($form, $form_state);
00031 }
00032
00033 function query() {
00034 $this->ensure_my_table();
00035 $this->add_additional_fields();
00036 }
00037
00038 function render($values) {
00039 $value = $this->get_value($values, 'cid');
00040 return $this->render_link($this->sanitize_value($value), $values);
00041 }
00042
00043 function render_link($data, $values) {
00044 $text = !empty($this->options['text']) ? $this->options['text'] : t('view');
00045 $comment = $this->get_value($values);
00046 $nid = $comment->nid;
00047 $cid = $comment->cid;
00048
00049 $this->options['alter']['make_link'] = TRUE;
00050 $this->options['alter']['html'] = TRUE;
00051
00052 if (!empty($cid)) {
00053 $this->options['alter']['path'] = "comment/" . $cid;
00054 $this->options['alter']['fragment'] = "comment-" . $cid;
00055 }
00056
00057 else if ($this->options['link_to_node']) {
00058 $this->options['alter']['path'] = "node/" . $nid;
00059 }
00060
00061 return $text;
00062 }
00063 }