views_handler_field_comment_node_link.inc

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

Definition of views_handler_field_comment_node_link.

File

modules/comment/views_handler_field_comment_node_link.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_field_comment_node_link.
  5. */
  6. /**
  7. * Handler for showing comment module's node link.
  8. *
  9. * @ingroup views_field_handlers
  10. */
  11. class views_handler_field_comment_node_link extends views_handler_field_entity {
  12. function construct() {
  13. parent::construct();
  14. // Add the node fields that comment_link will need..
  15. $this->additional_fields['nid'] = array(
  16. 'field' => 'nid',
  17. );
  18. $this->additional_fields['type'] = array(
  19. 'field' => 'type',
  20. );
  21. $this->additional_fields['comment'] = array(
  22. 'field' => 'comment',
  23. );
  24. }
  25. function option_definition() {
  26. $options = parent::option_definition();
  27. $options['teaser'] = array('default' => FALSE, 'bool' => TRUE);
  28. return $options;
  29. }
  30. function options_form(&$form, &$form_state) {
  31. $form['teaser'] = array(
  32. '#type' => 'checkbox',
  33. '#title' => t('Show teaser-style link'),
  34. '#default_value' => $this->options['teaser'],
  35. '#description' => t('Show the comment link in the form used on standard node teasers, rather than the full node form.'),
  36. );
  37. parent::options_form($form, $form_state);
  38. }
  39. function query() {
  40. $this->ensure_my_table();
  41. $this->add_additional_fields();
  42. }
  43. function render($values) {
  44. // Build fake $node.
  45. $node = $this->get_value($values);
  46. // Call comment.module's hook_link: comment_link($type, $node = NULL, $teaser = FALSE)
  47. // Call node by reference so that something is changed here
  48. comment_node_view($node, $this->options['teaser'] ? 'teaser' : 'full');
  49. // question: should we run these through: drupal_alter('link', $links, $node);
  50. // might this have unexpected consequences if these hooks expect items in $node that we don't have?
  51. // Only render the links, if they are defined.
  52. return !empty($node->content['links']['comment']) ? drupal_render($node->content['links']['comment']) : '';
  53. }
  54. }