views_handler_field_comment.inc

  1. 3.x modules/comment/views_handler_field_comment.inc
  2. 2.x modules/comment/views_handler_field_comment.inc

File

modules/comment/views_handler_field_comment.inc
View 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. function option_definition() {
  17. $options = parent::option_definition();
  18. $options['link_to_comment'] = array('default' => TRUE);
  19. return $options;
  20. }
  21. /**
  22. * Provide link-to-comment option
  23. */
  24. function options_form(&$form, &$form_state) {
  25. parent::options_form($form, $form_state);
  26. $form['link_to_comment'] = array(
  27. '#title' => t('Link this field to its comment'),
  28. '#description' => t('This will override any other link you have set.'),
  29. '#type' => 'checkbox',
  30. '#default_value' => $this->options['link_to_comment'],
  31. );
  32. }
  33. function render_link($data, $values) {
  34. if (!empty($this->options['link_to_comment']) && $data !== NULL && $data !== '') {
  35. $this->options['alter']['make_link'] = TRUE;
  36. $this->options['alter']['path'] = "node/". $values->{$this->aliases['nid']};
  37. $this->options['alter']['fragment'] = "comment-" . $values->{$this->aliases['cid']};
  38. }
  39. return $data;
  40. }
  41. function render($values) {
  42. return $this->render_link(check_plain($values->{$this->field_alias}), $values);
  43. }
  44. }