function ctools_rebuild_form in Chaos Tool Suite (ctools) 6
ctools' replacement of drupal_rebuild_form.
This change merely respects a form's wishes not to be cached.
1 call to ctools_rebuild_form()
- ctools_build_form in includes/
form.inc - Build a form, similar to drupal_get_form(). However, arguments to the form builder are not sent through. Instead, the $form_state can be given all the necessary data to fully utilize the form.
File
- includes/
form.inc, line 168 - CTools' replacements for Drupal's form functions.
Code
function ctools_rebuild_form($form_id, &$form_state, $args, $form_build_id = NULL) {
// Remove the first argument. This is $form_id.when called from
// drupal_get_form and the original $form_state when called from some AHAH
// callback. Neither is needed. After that, put in the current state.
array_unshift($args, 'placeholder');
$args[0] =& $form_state;
// Replaces placeholder.
// And the form_id.
array_unshift($args, $form_id);
if (isset($form_state['wrapper callback']) && function_exists($form_state['wrapper callback'])) {
// If there is a wrapper callback, we do not use drupal_retrieve_form.
// Instead, we call $form_id builder function directly. This means the args
// are *different* for forms used this way, which may not be ideal but
// is necessary right now.
$form = array();
$form_state['wrapper callback']($form, $form_state);
if (function_exists($form_id)) {
$form_id($form, $form_state);
}
}
else {
$form = call_user_func_array('drupal_retrieve_form', $args);
}
if (!isset($form_build_id)) {
// We need a new build_id for the new version of the form.
$form_build_id = 'form-' . md5(mt_rand());
}
$form['#build_id'] = $form_build_id;
// Flush form ID element cache because we may be rebuilding
// a form in a way that Drupal's FAPI isn't used to which
// causes unnecessary form ID changes.
form_clean_id(NULL, TRUE);
drupal_prepare_form($form_id, $form, $form_state);
if (empty($form['#no_cache'])) {
// Now, we cache the form structure so it can be retrieved later for
// validation. If $form_state['storage'] is populated, we'll also cache
// it so that it can be used to resume complex multi-step processes.
form_set_cache($form_build_id, $form, $form_state);
}
// Originally this called drupal_process_form, but all that happens there
// is form_builder and then submission; and the rebuilt form is not
// allowed to submit. Therefore, just do this:
$form['#post'] = $form_state['input'];
$form = form_builder($form_id, $form, $form_state);
return $form;
}