overlay_form_submit($form, &$form_state)Generic form submit handler.
When we are requested to close an overlay, we don't want Form API to perform any redirection once the submitted form has been processed.
When $form_state['redirect'] is set to FALSE, then Form API will simply re-render the form with the values still in its fields. And this is all we need to output the JavaScript that will tell the parent window to close the child dialog.
modules/overlay/overlay.module, line 362
<?php
function overlay_form_submit($form, &$form_state) {
$settings = &drupal_static(__FUNCTION__);
// Check if we have a request to close the overlay.
$args = overlay_request_dialog_close();
// Close the overlay if the overlay module has been disabled
if (!module_exists('overlay')) {
$args = overlay_request_dialog_close(TRUE);
}
// If there is a form redirect to a non-admin page, close the overlay.
if (isset($form_state['redirect'])) {
// A destination set in the URL trumps $form_state['redirect'].
if (isset($_GET['destination'])) {
$url = $_GET['destination'];
$url_settings = array();
}
elseif (is_array($form_state['redirect'])) {
$url = $form_state['redirect'][0];
$url_settings = $form_state['redirect'][1];
}
else {
$url = $form_state['redirect'];
$url_settings = array();
}
if (!path_is_admin($url)) {
$args = overlay_request_dialog_close(TRUE);
}
}
// If the overlay is to be closed, pass that information through JavaScript.
if ($args !== FALSE) {
if (!isset($settings)) {
$settings = array(
'overlayChild' => array(
'closeOverlay' => TRUE,
'statusMessages' => theme('status_messages'),
'args' => $args,
),
);
// Tell the child window to perform the redirection when requested to.
if (!empty($form_state['redirect'])) {
$settings['overlayChild']['redirect'] = url($url, $settings);
}
drupal_add_js($settings, array('type' => 'setting'));
}
// Tell FAPI to redraw the form without redirection after all submit
// callbacks have been processed.
$form_state['redirect'] = FALSE;
}
}
?>