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

File

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