Fix for CTools Modal Frames

  1. <?php
  2. // $Id$
  3. /**
  4. * Implementation of hook_menu().
  5. */
  6. function ctoolstest_menu() {
  7.   $items = array();
  8.   $items['test'] = array(
  9.     'title' => 'Ajax Test',
  10.     'page callback' => 'example_test_main',
  11.     'access arguments' => array('access content'),
  12.   );
  13.   $items['test/%ctools_js/go'] = array(
  14.     'page callback' => 'example_test_modal_callback',
  15.     'page arguments' => array(1),
  16.     'access arguments' => array('access content'),
  17.   );
  18.   return $items;
  19. }
  20.  
  21. /**
  22. * The main page that holds the link to the modal.
  23. */
  24. function example_test_main() {
  25.   // Load the modal library and add the modal javascript.
  26.   ctools_include('modal');
  27.   ctools_modal_add_js();
  28.  
  29.   $output = l('Load modal content', 'test/nojs/go', array(
  30.     'attributes' => array('class' => 'ctools-use-modal')));
  31.  
  32.   return $output;
  33. }
  34.  
  35. function example_test_modal_callback($js = FALSE) {
  36.   if ($js) {
  37.     ctools_include('ajax');
  38.     ctools_include('modal');
  39.     $form_state = array(
  40.       'ajax' => TRUE,
  41.       'title' => t('Login'),
  42.     );
  43.     $output = ctools_modal_form_wrapper('user_login', $form_state);
  44.     if (empty($output)) {
  45.       $output[] = ctools_modal_command_loading();
  46.       $output[] = ctools_ajax_command_redirect('user');
  47.     }
  48.     ctools_ajax_render($output);
  49.   }
  50.   else {
  51.     return drupal_get_form('user_login');
  52.   }
  53. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.