function flagging_dialog_process_form_result in Flagging Form 7
Same name and namespace in other branches
- 7.3 flagging_dialog.module \flagging_dialog_process_form_result()
Handles submission of the form.
2 calls to flagging_dialog_process_form_result()
- flagging_dialog_delete_flagging in ./
flagging_dialog.module - Menu callback.
- flagging_dialog_edit_flagging in ./
flagging_dialog.module - Menu callback.
File
- ./
flagging_dialog.module, line 206 - Provides menu callbacks for displaying the flagging forms in a dialog box.
Code
function flagging_dialog_process_form_result($form, $form_state, $flag, $content_id) {
$commands = array();
// The following line reloads the 'dialog' and 'flagging_dialog' libraries.
// Why? Because there's a bug in Drupal/DialogAPI:
//
// When the JavaScript aggregator is turned on, DialogAPI (in
// dialog_ajax_render_alter()) tells the browser to load drupal.js and
// ajax.js as well, and this blows away the additions dialog.js did to some
// data structures there (Drupal.{theme,ajax}.prototype). So we re-introduce
// these additions.
//
// See http://drupal.org/node/XXXX
drupal_add_library('flagging_dialog', 'flagging_dialog');
if (!empty($form_state['executed'])) {
// The form has been submitted. Either redirect to a new url or close the
// dialog.
if (is_array($form_state['redirect'])) {
$target = $form_state['redirect'][0];
}
else {
$target = $form_state['redirect'];
}
// If there's an ajax version for the target path, use it.
$try = menu_get_item($target . '/ajax');
if ($try && strpos($try['path'], '/ajax') !== FALSE) {
// Yes, there is. Do an "internal" redirect.
$target = $target . '/ajax';
_flagging_dialog_set_drupal_path($target);
menu_execute_active_handler($target);
drupal_exit();
// An alternative is to do a roundtrip using
// dialog_command_boxed_redirect()
// See http://drupal.org/node/XXXX
}
else {
// No, there's no ajax page to go to. Close the dialog, and
// update the flag link.
$commands[] = dialog_command_dismiss();
$commands[] = flagging_dialog_command_update_link($flag, $content_id, !empty($form_state['flag_status_has_changed']));
}
}
else {
// The form hasn't been submitted. So we just need to display it.
dialog_display(TRUE);
// Make dialog_ajax_render_alter() run.
$commands[] = dialog_command_display($form, array(
'title' => drupal_get_title(),
));
}
$output = array(
'#type' => 'ajax',
'#commands' => $commands,
);
return $output;
}