You are here

function modal_forms_login in Modal forms (with ctools) 7

Same name and namespace in other branches
  1. 6 modal_forms.pages.inc \modal_forms_login()

A modal user login callback.

3 string references to 'modal_forms_login'
modal_forms_admin_settings in ./modal_forms.admin.inc
General configuration form for controlling the modal_forms behaviour.
modal_forms_menu in ./modal_forms.module
Implements hook_menu().
_modal_forms_doheader in ./modal_forms.module
Loads the various js and css files.

File

./modal_forms.pages.inc, line 11
Page callbacks for the modal_forms module.

Code

function modal_forms_login($js = NULL) {

  // Fall back if $js is not set.
  if (!$js) {
    return drupal_get_form('user_login');
  }
  ctools_include('modal');
  ctools_include('ajax');
  $form_state = array(
    // 'title' => t('Log in'),.
    'ajax' => TRUE,
  );

  // Check to make sure the user has not logged in on another session.
  // If that is the case just reload the page.
  if (user_is_logged_in()) {
    $output = array();
    ctools_add_js('ajax-responder');
    $output[] = ctools_ajax_command_reload();
  }
  else {
    $output = ctools_modal_form_wrapper('user_login', $form_state);
  }
  if (!empty($form_state['executed'])) {

    // We'll just overwrite the form output if it was successful.
    $output = array();
    ctools_add_js('ajax-responder');
    $output[] = ctools_modal_command_dismiss();
    if (isset($_GET['destination'])) {
      $output[] = ctools_ajax_command_redirect($_GET['destination']);
    }
    elseif (module_exists('login_destination')) {
      $destination = login_destination_get_destination('login');
      $output[] = ctools_ajax_command_redirect(is_array($destination) ? $destination[0] : $destination);
    }
    else {
      $output[] = ctools_ajax_command_reload();
    }
  }
  print ajax_render($output);
}