'colorbox_node_output', 'page arguments' => array(1), 'access arguments' => array('access content'), 'load arguments' => array('%map'), 'delivery callback' => 'ajax_deliver', 'theme callback' => 'ajax_base_page_theme', 'type' => MENU_CALLBACK, ); return $items; } /* * 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. */ function colorbox_node_output($path) { // @TODO, we should be able to use this for users too, // Lets beef this up and make it more intelligent around // the system path. //$_GET['destination'] = $path; // Lets determine if this is a webform and add the // nid to dynamically add ajax support. $args = explode('/', $path); if ($args[0] == 'node' && is_numeric($args[1])) { $GLOBALS['colorbox_node_webform'] = $args[1]; } // Fetch our callback based on our path. $page_callback_result = menu_execute_active_handler($path, FALSE); // If the callback is an integer, we have an error, lets // render that out as a command. if (is_int($page_callback_result)) { $commands = ajax_prepare_response($page_callback_result); } else { $commands = array(); // Is we have an array, lets assume we need to render it out. if (is_array($page_callback_result)) { $html = drupal_render($page_callback_result); $commands[] = ajax_command_html('#cboxNode', $html); } else { $commands[] = ajax_command_html('#cboxNode', $page_callback_result); } // Setup our parameters to pass along to our colorbox. $params = array(); $params['inline'] = TRUE; $params['href'] = '#cboxNode'; $params['onClosed'] = 'close'; if (isset($_GET['width'])) $params['innerWidth'] = (int) $_GET['width']; if (isset($_GET['height'])) $params['innerHeight'] = (int) $_GET['height']; $params = json_encode($params); $javascript = ' '; $commands[] = ajax_command_html('#cboxNodeJS', $javascript); } // Render our commands out to the browser. return array('#type' => 'ajax', '#commands' => $commands); } /* * Takes a path as an array of all our arguments from the * url structure. We then put that structure back together, * find our system path and then return it. */ function colorbox_node_url_load($arg, $path = array()) { // First lets remove colorbox array_shift($path); // Lets determine if we have a prefix from our languages. if (module_exists('locale') && function_exists('language_url_split_prefix')) { // Get our language list to pass into our url splitter. $languages = language_list(); // Turn the path into a string so we can then remove our prefix. $path_string = implode('/', $path); $language_path = language_url_split_prefix($path_string, $languages); // Separate out the returned path and language. We should always // have two indexes, the first is the language, second is the path. $language = $language_path[0] ? $language_path[0]->language : ''; $final_path = $language_path[1]; // Lets find our path based on the current translation. return drupal_get_normal_path($final_path, $language); } // Now lets buld our path to return our system path, return drupal_get_normal_path(implode('/', $path)); } /* * Implements hook_form_alter(). */ function colorbox_node_form_alter(&$form, &$form_state, $form_id) { // Determine if our webform as been set for display inside a // colorbox modal window. if (isset($GLOBALS['colorbox_node_webform']) && $GLOBALS['colorbox_node_webform']) { // $make_form_ajax = false; // $webform_id = 'webform_client_form_'. $GLOBALS['colorbox_node_webform']; if ($form_id == $webform_id) { $make_form_ajax = true; } elseif (is_numeric($GLOBALS['colorbox_node_webform'])) { $tmp_node = node_load($GLOBALS['colorbox_node_webform']); if ($tmp_node !== FALSE) { $webform_id = $tmp_node->type . '_node_form'; if ($form_id == $webform_id) { $make_form_ajax = true; array_unshift($form['#validate'], "colorbox_js_node_form_validate"); } } } // If we are altering our current webform to be displayed // inside a modal box, lets add ajax support. if ($make_form_ajax == true) { // Add our ajax support for this webform dynamically. $form['#prefix'] = '
'; $form['#suffix'] = '
'; $form['actions']['submit']['#id'] = 'cboxSubmit'; $form['actions']['submit']['#ajax'] = array( 'callback' => 'colorbox_node_webform_js_submit', 'wrapper' => 'cboxNodeWrapper', 'method' => 'replace', 'effect' => 'fade', ); } } } /* * Validation function that must called first when using colorbox_node with a node. * --> If this is NOT called at first when validation, the following error will occur: * node_form_validate function not found!!!! */ function colorbox_js_node_form_validate($form, &$form_state) { $file = drupal_get_path('module', 'node') . '/node.pages.inc'; require_once DRUPAL_ROOT . '/' . $file; } /* * Javascript submit handler for our webform. */ function colorbox_node_webform_js_submit($form, &$form_state) { // If we have a failure or success, lets resize the modal box again since // it could grow/lose in height with the error/success messages. // @TODO: Change the dynamic resizing only if the user wants it. $javascript = ' '; // We need a smarter dynamnic resize in case the user doesn't // want it to resize automatically. Or if its a very large form // and it would extend past the page. $javascript = ''; // If we have a sid, then the form has been successfully submitted. // Lets display our confirmation message. if (!form_get_errors()) { $node = node_load($form_state['values']['details']['nid']); if ($node !== FALSE) { // Find out what we should be doing for the webform. if($node->webform['redirect_url'] == '') { // Display a confirmation message. $markup = check_markup($node->webform['confirmation'], $node->webform['confirmation_format'], '', TRUE) . $javascript; } elseif($node->webform['redirect_url'] == '') { // Not sure what to do here? // Display confirmation? $markup = ''; } else { // We are doing a redirect so we need to close the colorbox // and then force a window.location on the passed in URL. $markup = ' '; } } else { // We are doing a redirect so we need to close the colorbox // and then DO NOT force a window.location. The location will be determined by // the redirect attribute in the form... $markup = ' '; } // Return our markup. $confirmation = array( '#type' => 'markup', '#markup' => $markup, ); return $confirmation; } else { // We just pass through our $form return $form; } } /** * Implements hook_entity_info_alter(). */ function colorbox_node_entity_info_alter(&$entity_info) { $entity_info['node']['view modes']['colorbox'] = array( 'label' => t('Colorbox'), 'custom settings' => TRUE, ); } /* * Implements hook_page_alter(). */ function colorbox_node_page_alter(&$page) { $page['page_bottom']['cboxNode'] = array( '#type' => 'markup', '#markup' => '
', ); } /** * Implements hook_views_api(). */ function colorbox_node_views_api() { return array( 'api' => 2, 'path' => drupal_get_path('module', 'colorbox_node') . '/views', ); }