diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index 49692d9..f9f56a4 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -664,6 +664,9 @@ public function prepareForm($form_id, &$form, &$form_state) { if ($form_state['method'] == 'get' && !isset($form['#method'])) { $form['#method'] = 'get'; } + // For certain forms like a search for or exposed filters, we want to make + // a clean GET request without hidden values as query parameters. + $clean_get = $form['#method'] == 'get' && $form['#token'] === FALSE && $form['#build_id'] === FALSE; // Generate a new #build_id for this form, if none has been set already. // The form_build_id is used as key to cache a particular build of the form. @@ -674,16 +677,20 @@ public function prepareForm($form_id, &$form, &$form_state) { if (!isset($form['#build_id'])) { $form['#build_id'] = 'form-' . Crypt::randomBytesBase64(); } - $form['form_build_id'] = array( - '#type' => 'hidden', - '#value' => $form['#build_id'], - '#id' => $form['#build_id'], - '#name' => 'form_build_id', - // Form processing and validation requires this value, so ensure the - // submitted form value appears literally, regardless of custom #tree - // and #parents being set elsewhere. - '#parents' => array('form_build_id'), - ); + // Form constructors may explicitly set #build_id to FALSE when processing + // and validation are irrelevant to the form, such as GET search forms. + if (!$clean_get) { + $form['form_build_id'] = array( + '#type' => 'hidden', + '#value' => $form['#build_id'], + '#id' => $form['#build_id'], + '#name' => 'form_build_id', + // Form processing and validation requires this value, so ensure the + // submitted form value appears literally, regardless of custom #tree + // and #parents being set elsewhere. + '#parents' => array('form_build_id'), + ); + } // Add a token, based on either #token or form_id, to any form displayed to // authenticated users. This ensures that any submitted form was actually @@ -714,7 +721,7 @@ public function prepareForm($form_id, &$form, &$form_state) { } } - if (isset($form_id)) { + if (isset($form_id) && !$clean_get) { $form['form_id'] = array( '#type' => 'hidden', '#value' => $form_id,