You are here

function colorbox_node_output in Colorbox Node 7.3

Same name and namespace in other branches
  1. 7 colorbox_node.module \colorbox_node_output()
  2. 7.2 colorbox_node.module \colorbox_node_output()

Displays a node view without the page template. Takes the path as our argument and from that we will determine the internal path and node id.

1 call to colorbox_node_output()
colorbox_node_ajax_submit in ./colorbox_node.module
Handles all the ajax forms and runs them through this central function to either return the form with error messages, or to close the colorbox and populate our messages div container.
1 string reference to 'colorbox_node_output'
colorbox_node_menu in ./colorbox_node.module
Implements hook_menu().

File

./colorbox_node.module, line 246
Creates a menu callback with support for displaying a node inside of a colorbox.

Code

function colorbox_node_output($path) {

  // Tell others our modal window is active
  drupal_static('colorbox_node_is_active', TRUE);

  // Setup our return destination.
  if (!isset($_GET['destination'])) {
    $_GET['destination'] = $path;
  }

  // Change our super global for the rest of the
  // bootstrap process.
  $_GET['q'] = $path;

  // Fetch our callback based on our path.
  $page_callback_result = menu_execute_active_handler($path, FALSE);

  // Lets include our context execution.
  if (module_exists('context')) {
    if ($plugin = context_get_plugin('condition', 'colorbox_node')) {
      $plugin
        ->execute('view');
    }
  }
  $commands = array();

  // Is we have an array, lets assume we need to render it out.
  if (is_array($page_callback_result)) {
    if (isset($page_callback_result['nodes'])) {
      foreach ($page_callback_result['nodes'] as $nid => $tmp_node) {
        if (isset($tmp_node['#view_mode'])) {
          $node_view = $tmp_node['#node'];
          $node_view_array = node_view($node_view, 'colorbox');
          if (module_exists('comment')) {
            $node_view_array['comments'] = comment_node_page_additions($node_view);
          }
          $rendered_node = drupal_render($node_view_array);
          $page_callback_result['nodes'][$nid] = array(
            '#markup' => $rendered_node,
          );
        }
      }
    }
  }

  // Load up our regions if enabled.
  if (variable_get('colorbox_node_regions', FALSE) == TRUE) {
    drupal_set_page_content($page_callback_result);
    $page_callback_result = element_info('ajax');

    // Modules can add elements to $page as needed in hook_page_build().
    foreach (module_implements('page_build') as $module) {
      $function = $module . '_page_build';
      $function($page_callback_result);
    }

    // Modules alter the $page as needed. Blocks are populated into regions like
    // 'sidebar_first', 'footer', etc.
    drupal_alter('page', $page_callback_result);
  }

  // Allow other modules to alter the colorbox node callback
  drupal_alter('colorbox_node_page_callback_result', $page_callback_result);
  $html = is_string($page_callback_result) ? $page_callback_result : drupal_render($page_callback_result);
  $commands[] = ajax_command_html('#cboxLoadedContent', $html);

  // Add the status messages inside the new content's wrapper element, so that
  // on subsequent Ajax requests, it is treated as old content.
  $commands[] = ajax_command_prepend('#cboxLoadedContent', theme('status_messages'));

  // Render our commands out to the browser.
  return array(
    '#type' => 'ajax',
    '#commands' => $commands,
  );
}