Was just following an issue in which, making a redirection on the onsubmit callback was not showing status messages I was setting prior instructing this redirect.

It took me a bit to figure out but the reason is quite obvious:

    'statusMessages' => theme('status_messages'),

this line on modalframe_close_dialog($args = NULL) is calling the theme function and then clearing the status messages from the session.

As this function does not give us the option to clear or not clear the issue queue I am thinking of doing a custom theme('modalframe_status_messages', $clear_queue) in which we could, if we want to, pass an optional argument which we can also pass to the modalframe_close_dialog().

I know this is a bit off, but it may be a desired behavior.

Thoughts?

Comments

hanoii’s picture

I have sorted out this in the module I am using the modalframe api by doing the following:

  if ($redirect) {
    // we save the messages to be displayed on the redirect as well
    $_SESSION['modalframe_login_messages_backup'] = $_SESSION['messages'];
  }
  modalframe_close_dialog(array(
    'redirect' => $redirect,
  ));

so this will send the redirect info to the JS part of the module.

I am backuping the session messages
and then I am doing:


  if (!isset($_SESSION['messages']) && isset($_SESSION['modalframe_login_messages_backup'])) {
    $_SESSION['messages'] = $_SESSION['modalframe_login_messages_backup'];
  }
  unset($_SESSION['modalframe_login_messages_backup']);

on hook_init()

And finally, in the JS part of my module:

function onSubmitCallbackModalframeLogin (args, statusMessages)  {
  if (args.redirect) {
    if (args.redirect == '.') {
      location.reload();
    }
    else {
      location.replace(args.redirect);
    }
  }
  else {
    if (statusMessages) {
      // only doing something with status messages if we are not redirecting
    }
  }
}

This works nicely, so leaving here for reference, but still, shall something like this should be included in the api?

crea’s picture

Subs

dsnopek’s picture

Version: 6.x-1.7 » 7.x-1.x-dev
Category: Support request » Feature request
Issue summary: View changes

You're right, there probably should be a way to prevent modalframe_close_dialog() from wiping out the messages. Let's try to address this in the Drupal 7 version first.