function ctools_modal_form_wrapper

Wrap a form so that we can use it properly with AJAX. Essentially if the form wishes to render, it automatically does that, otherwise it returns the render array so we can see submission results.

Parameters

array $form: An associative array containing the structure of the form.

array $form_state: An associative array containing the current state of the form. If the 'reset_html_ids' key is set to TRUE, it will prevent HTML IDs in forms from being incremented.

Return value

mixed The output of the form, if it was rendered. If $form_state['ajax'] is set, this will use ctools_modal_form_render so it will be a $command object suitable for ajax_render already.

If the form was not rendered, the raw render array will be returned.

If ajax is set the form will never be redirected.

3 calls to ctools_modal_form_wrapper()
ctools_access_ajax_add in includes/context-access-admin.inc
AJAX callback to add a new access test to the list.
ctools_access_ajax_edit in includes/context-access-admin.inc
AJAX callback to edit an access test in the list.
ctools_ajax_sample_login in ctools_ajax_sample/ctools_ajax_sample.module
A modal login callback.

File

includes/modal.inc, line 210

Code

function ctools_modal_form_wrapper($form_id, &$form_state) {
    // Since this will run again on form rebuild while still in the modal, prevent
    // form IDs from being incremented.
    // @todo https://drupal.org/node/1305882
    if (!empty($form_state['reset_html_ids']) && !empty($_POST['ajax_html_ids'])) {
        unset($_POST['ajax_html_ids']);
    }
    // This won't override settings already in.
    $form_state += array(
        're_render' => FALSE,
        'no_redirect' => !empty($form_state['ajax']),
    );
    $output = drupal_build_form($form_id, $form_state);
    if (!empty($form_state['ajax']) && (!$form_state['executed'] || $form_state['rebuild'])) {
        return ctools_modal_form_render($form_state, $output);
    }
    return $output;
}