diff options
-rw-r--r-- | includes/ajax.inc | 4 | ||||
-rw-r--r-- | includes/form.inc | 24 | ||||
-rw-r--r-- | modules/book/book.module | 9 | ||||
-rw-r--r-- | modules/book/book.pages.inc | 2 | ||||
-rw-r--r-- | modules/poll/poll.module | 12 | ||||
-rw-r--r-- | modules/simpletest/tests/form.test | 2 | ||||
-rw-r--r-- | modules/simpletest/tests/form_test.module | 2 | ||||
-rw-r--r-- | modules/upload/upload.module | 10 |
8 files changed, 31 insertions, 34 deletions
diff --git a/includes/ajax.inc b/includes/ajax.inc index 464a3c800..80e6bbce1 100644 --- a/includes/ajax.inc +++ b/includes/ajax.inc @@ -366,7 +366,7 @@ function ajax_deliver($page_callback_result) { * None. Additional code is added to the header of the page using * drupal_add_js(). */ -function ajax_process_form($element) { +function ajax_process_form($element, &$form_state) { $js_added = &drupal_static(__FUNCTION__, array()); // Add a reasonable default event handler if none was specified. @@ -437,7 +437,7 @@ function ajax_process_form($element) { drupal_add_js(array('ajax' => array($element['#id'] => $ajax_binding)), 'setting'); $js_added[$element['#id']] = TRUE; - $element['#cache'] = TRUE; + $form_state['cache'] = TRUE; } return $element; } diff --git a/includes/form.inc b/includes/form.inc index f5ce76b5f..1e42f6eae 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -112,7 +112,11 @@ function drupal_get_form($form_id) { * can have unexpected effects. The 'get' method should only be used on * forms that do not change data, as that is exclusively the domain of post. * - no_redirect: If set to TRUE the form will NOT perform a drupal_goto(), - * even if a redirect is set. + * even if 'redirect' is set. + * - cache: If set to TRUE the original, unprocessed form structure will be + * cached, which allows to rebuild the entire form from cache. + * - no_cache: If set to TRUE the form will NOT be cached, even if 'cache' is + * set. * - always_process: If TRUE and the method is GET, a form_id is not * necessary. This should only be used on RESTful GET forms that do NOT * write data, as this could lead to security issues. It is useful so that @@ -192,7 +196,7 @@ function drupal_build_form($form_id, &$form_state) { drupal_prepare_form($form_id, $form, $form_state); // Store a copy of the unprocessed form for caching and indicate that it - // is cacheable if #cache will be set. + // is cacheable in case $form_state['cache'] is set. $original_form = $form; $cacheable = TRUE; } @@ -204,9 +208,11 @@ function drupal_build_form($form_id, &$form_state) { // reference. drupal_process_form($form_id, $form, $form_state); - if ($cacheable && !empty($form_state['cache']) && empty($form['#no_cache'])) { - // Caching is done past drupal_process_form so #process callbacks can - // set #cache. + // After processing the form, the form builder or a #process callback may + // have set $form_state['cache'] to indicate that the original form and the + // $form_state shall be cached. But the form may only be cached if the + // special 'no_cache' property is not set to TRUE. + if ($cacheable && !empty($form_state['cache']) && empty($form_state['no_cache'])) { form_set_cache($form_build_id, $original_form, $form_state); } } @@ -299,7 +305,7 @@ function drupal_rebuild_form($form_id, &$form_state, $form_build_id = NULL) { $form['#build_id'] = $form_build_id; drupal_prepare_form($form_id, $form, $form_state); - if (empty($form['#no_cache'])) { + if (empty($form_state['no_cache'])) { // We cache the form structure so it can be retrieved later for validation. // If $form_state['storage'] is populated, we also cache it so that it can // be used to resume complex multi-step processes. @@ -1121,12 +1127,6 @@ function form_builder($form_id, $element, &$form_state) { // Internet Explorer button-click scenario. _form_builder_ie_cleanup($element, $form_state); - // If some callback set #cache, we need to flip a flag so later it - // can be found. - if (!empty($element['#cache'])) { - $form_state['cache'] = $element['#cache']; - } - // If there is a file element, we need to flip a flag so later the // form encoding can be set. if (isset($element['#type']) && $element['#type'] == 'file') { diff --git a/modules/book/book.module b/modules/book/book.module index 08abba08a..9c0778b89 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -360,8 +360,7 @@ function book_get_books() { * @see book_pick_book_submit() * @see book_submit() */ -function book_form_alter(&$form, $form_state, $form_id) { - +function book_form_alter(&$form, &$form_state, $form_id) { if (!empty($form['#node_edit_form'])) { // Add elements to the node form. $node = $form['#node']; @@ -375,7 +374,7 @@ function book_form_alter(&$form, $form_state, $form_id) { } if ($access) { - _book_add_form_elements($form, $node); + _book_add_form_elements($form, $form_state, $node); $form['book']['pick-book'] = array( '#type' => 'submit', '#value' => t('Change book (update list of parents)'), @@ -439,9 +438,9 @@ function _book_parent_select($book_link) { /** * Build the common elements of the book form for the node and outline forms. */ -function _book_add_form_elements(&$form, $node) { +function _book_add_form_elements(&$form, &$form_state, $node) { // Need this for AJAX. - $form['#cache'] = TRUE; + $form_state['cache'] = TRUE; $form['book'] = array( '#type' => 'fieldset', diff --git a/modules/book/book.pages.inc b/modules/book/book.pages.inc index 1e360ab8c..76454aa9f 100644 --- a/modules/book/book.pages.inc +++ b/modules/book/book.pages.inc @@ -117,7 +117,7 @@ function book_outline_form($form, &$form_state, $node) { } $form['#node'] = $node; $form['#id'] = 'book-outline'; - _book_add_form_elements($form, $node); + _book_add_form_elements($form, $form_state, $node); $form['book']['#collapsible'] = FALSE; diff --git a/modules/poll/poll.module b/modules/poll/poll.module index 9242bcf9f..18be700f2 100644 --- a/modules/poll/poll.module +++ b/modules/poll/poll.module @@ -211,16 +211,14 @@ function poll_field_extra_fields($bundle) { /** * Implement hook_form(). */ -function poll_form($node, $form_state) { +function poll_form($node, &$form_state) { global $user; $admin = user_access('administer nodes') || user_access('edit any poll content') || (user_access('edit own poll content') && $user->uid == $node->uid); $type = node_type_get_type($node); - $form = array( - '#cache' => TRUE, - ); + $form_state['cache'] = TRUE; if (isset($form_state['choice_count'])) { $choice_count = $form_state['choice_count']; @@ -658,7 +656,7 @@ function poll_view_voting($form, &$form_state, $node, $block = FALSE) { // Set form caching because we could have multiple of these forms on // the same page, and we want to ensure the right one gets picked. - $form['#cache'] = TRUE; + $form_state['cache'] = TRUE; // Provide a more cleanly named voting form theme. $form['#theme'] = 'poll_vote'; @@ -845,6 +843,8 @@ function template_preprocess_poll_bar(&$variables) { * @see poll_cancel() */ function poll_cancel_form($form, &$form_state, $nid) { + $form_state['cache'] = TRUE; + // Store the nid so we can get to it in submit functions. $form['#nid'] = $nid; @@ -854,8 +854,6 @@ function poll_cancel_form($form, &$form_state, $nid) { '#submit' => array('poll_cancel') ); - $form['#cache'] = TRUE; - return $form; } diff --git a/modules/simpletest/tests/form.test b/modules/simpletest/tests/form.test index 895084f6b..ed556c540 100644 --- a/modules/simpletest/tests/form.test +++ b/modules/simpletest/tests/form.test @@ -432,7 +432,7 @@ class FormsFormStorageTestCase extends DrupalWebTestCase { } /** - * Tests using the form with an activated #cache property. + * Tests using the form with an activated $form_state['cache'] property. */ function testFormCached() { $user = $this->drupalCreateUser(array('access content')); diff --git a/modules/simpletest/tests/form_test.module b/modules/simpletest/tests/form_test.module index efd26b773..5e420fc4a 100644 --- a/modules/simpletest/tests/form_test.module +++ b/modules/simpletest/tests/form_test.module @@ -329,7 +329,7 @@ function form_storage_test_form($form, &$form_state) { if (isset($_REQUEST['cache'])) { // Manually activate caching, so we can test that the storage keeps working // when it's enabled. - $form['#cache'] = TRUE; + $form_state['cache'] = TRUE; } return $form; diff --git a/modules/upload/upload.module b/modules/upload/upload.module index 93162c5ca..fb5341f21 100644 --- a/modules/upload/upload.module +++ b/modules/upload/upload.module @@ -210,7 +210,7 @@ function upload_node_form_submit(&$form, &$form_state) { } } -function upload_form_alter(&$form, $form_state, $form_id) { +function upload_form_alter(&$form, &$form_state, $form_id) { if ($form_id == 'node_type_form' && isset($form['identity']['type'])) { $form['workflow']['upload'] = array( '#type' => 'radios', @@ -256,7 +256,7 @@ function upload_form_alter(&$form, $form_state, $form_id) { } } else { - $form['attachments']['wrapper'] += _upload_form($node); + $form['attachments']['wrapper'] += _upload_form($node, $form_state); } $form['#submit'][] = 'upload_node_form_submit'; } @@ -529,12 +529,12 @@ function upload_save($node) { } } -function _upload_form($node) { +function _upload_form($node, &$form_state) { global $user; + $form_state['cache'] = TRUE; $form = array( '#theme' => 'upload_form_new', - '#cache' => TRUE, '#prefix' => '<div id="attach-wrapper">', '#suffix' => '</div>', ); @@ -669,7 +669,7 @@ function upload_js() { $node->files = $files; - $form = _upload_form($node); + $form = _upload_form($node, $form_state); unset($cached_form['attachments']['wrapper']['new']); $cached_form['attachments']['wrapper'] = array_merge($cached_form['attachments']['wrapper'], $form); |