| Commit | Line | Data |
|---|---|---|
| fe44beb7 | 1 | <?php |
| fe44beb7 EM |
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); | |
| c2cac4bd | 11 | if (!empty($this->options['link_to_comment'])) { |
| fe44beb7 EM |
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'), | |
| d8c64e8b | 30 | '#description' => t('This will override any other link you have set.'), |
| fe44beb7 EM |
31 | '#type' => 'checkbox', |
| 32 | '#default_value' => $this->options['link_to_comment'], | |
| 33 | ); | |
| 34 | } | |
| 35 | ||
| 36 | function render_link($data, $values) { | |
| c3f56c85 | 37 | if (!empty($this->options['link_to_comment']) && $data !== NULL && $data !== '') { |
| d8c64e8b | 38 | $this->options['alter']['make_link'] = TRUE; |
| 856b57cd | 39 | $this->options['alter']['path'] = "node/". $values->{$this->aliases['nid']}; |
| d8c64e8b | 40 | $this->options['alter']['fragment'] = "comment-" . $values->{$this->aliases['cid']}; |
| fe44beb7 | 41 | } |
| d8c64e8b EM |
42 | |
| 43 | return $data; | |
| fe44beb7 EM |
44 | } |
| 45 | ||
| 46 | function render($values) { | |
| 47 | return $this->render_link(check_plain($values->{$this->field_alias}), $values); | |
| 48 | } | |
| 49 | } |