Sunday, February 2, 2014

Drupal 7 - Using Ctools modal popup node view with comments

<?php
/**
 *  Implements of hook_menu()
 
*/
function hook_menu() {
  $items = array();
  $items['pop/%ctools_js/%'] = array(
    'page arguments' => array(1, 2),
    'page callback' => 'pop_modal_page',
    'access callback' => TRUE,
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}

function pop_modal_page($js = NULL, $nid) {
  if ($js) {
    ctools_include('modal');
    ctools_include('ajax');
  } else return 'Your browser does not support javascript';

  $node = node_load($nid);
  $node_view = node_view($node);
  $node_view['comments'] = comment_node_page_additions($node);
  $contents = render($node_view); 
  return ctools_modal_render($node->title, $contents) ;
}