function modalframe_form_alter in Modal Frame API 7
Same name and namespace in other branches
- 6 modalframe.module \modalframe_form_alter()
Implementation of hook_form_alter().
The main goal of this function is to set $form_state['redirect'] to FALSE when a submitted form performs a request to close the modal dialog where it's been processed.
A few notes on the workflow we're using here:
- Form API is requested to build a form. Then invokes all hook_form_alter() implementations.
- Here we install an after_build callback because still, there may be other modules that can add submit handlers from their own hook_form_alter().
- Ok, form API processes all hook_form_alter() implementations, then invokes our after_build callback where we can scan the whole form structure in search for elements that have submit handlers. We want to append our own submit handler so that we can catch requests to close the active child dialog performed by other modules using the API modalframe_close_dialog() from their submit handlers.
- Our submit handler has been installed using an after_build callback because this is kind of low level technique, which is not often used by contributed modules, and chances are that our submit handler is executed after all potential places from where modalframe_close_dialog() can be used by a external module using the "Modal Frame API". Also, this way our module does not depend on the order module hooks are being invoked by Drupal.
See also
File
- ./
modalframe.module, line 170 - Provides an API to render an iframe within a modal dialog based on the jQuery UI Dialog plugin.
Code
function modalframe_form_alter(&$form, &$form_state, $form_id) {
// Here we simply want to install a form after_build callback.
if (!isset($form['#after_build'])) {
$form['#after_build'] = array();
}
$form['#after_build'][] = 'modalframe_form_after_build';
}