Helper module to use views comments with AJAX

Public

</> CopyGet raw version
php
  1. /**
  2.  * Implements hook_preprocess_page().
  3.  */
  4. function mymodule_preprocess_page(&$vars, $hook) {
  5. // Reload the javascript into the scripts because views AJAX will not work.
  6. $vars['scripts'] = drupal_get_js();
  7. }
  8.  
  9. /**
  10.  * Implements hook_node_view().
  11.  */
  12. function mymodule_node_view($node, $view_mode, $langcode) {
  13. // Should we display the comment form?
  14. if ($node->comment && $view_mode == 'full' && node_is_page($node) && empty($node->in_preview)) {
  15. // Force the pager limit, because after the new comment we will redirect to
  16. // a wrong page if comment module calculate it from the content type
  17. // settings form.
  18. variable_set('comment_default_per_page_' . $node->type, PHP_INT_MAX);
  19. // Replace the original comment list with the created view.
  20. $node->content['comments']['comments'] = array(
  21. '#markup' => views_embed_view('created_views_machine_name', 'created_views_display_name', $node->nid),
  22. );
  23. }
  24. }