• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

modules/comment/views_handler_field_comment_node_link.inc

00001 <?php
00007 class views_handler_field_comment_node_link extends views_handler_field_entity {
00008   function construct() {
00009     parent::construct();
00010 
00011     // Add the node fields that comment_link will need..
00012     $this->additional_fields['nid'] = array(
00013       'field' => 'nid',
00014     );
00015     $this->additional_fields['type'] = array(
00016       'field' => 'type',
00017     );
00018     $this->additional_fields['comment'] = array(
00019       'field' => 'comment',
00020     );
00021   }
00022 
00023   function option_definition() {
00024     $options = parent::option_definition();
00025     $options['teaser'] = array('default' => 0);
00026     return $options;
00027   }
00028 
00029   function options_form(&$form, &$form_state) {
00030     $form['teaser'] = array(
00031       '#type' => 'checkbox',
00032       '#title' => t('Show teaser-style link'),
00033       '#default_value' => $this->options['teaser'],
00034       '#description' => t('Show the comment link in the form used on standard node teasers, rather than the full node form.'),
00035       '#fieldset' => 'more',
00036     );
00037 
00038     parent::options_form($form, $form_state);
00039   }
00040 
00041   function query() {
00042     $this->ensure_my_table();
00043     $this->add_additional_fields();
00044   }
00045 
00046   function render($values) {
00047     // Build fake $node.
00048     $node = $this->get_value($values);
00049 
00050     // Call comment.module's hook_link: comment_link($type, $node = NULL, $teaser = FALSE)
00051     // Call node by reference so that something is changed here
00052     comment_node_view($node, $this->options['teaser'] ? 'teaser' : 'full');
00053     // question: should we run these through:    drupal_alter('link', $links, $node);
00054     // might this have unexpected consequences if these hooks expect items in $node that we don't have?
00055 
00056     // Only render the links, if they are defined.
00057     return !empty($node->content['links']['comment']) ? drupal_render($node->content['links']['comment']) : '';
00058   }
00059 }

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1