diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index 8e59e0f..45a1cc6 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -192,7 +192,7 @@ public function getForm($form_arg) { */ public function buildForm($form_id, array &$form_state) { // Ensure some defaults; if already set they will not be overridden. - $form_state = NestedArray::mergeDeep($form_state, $this->getFormStateDefaults()); + $form_state = NestedArray::mergeDeep($this->getFormStateDefaults(), $form_state); // Ensure the form ID is prepared. $form_id = $this->getFormId($form_id, $form_state); diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php index 8b578b8..784d926 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php @@ -139,10 +139,7 @@ public function renderExposedForm($block = FALSE) { } $form_state['exposed_form_plugin'] = $this; - $form_builder = \Drupal::formBuilder(); - $form_state['build_info']['args'] = array(); - $form_object = $form_builder->getFormId('\Drupal\views\Form\ViewsExposedForm', $form_state); - $form = $form_builder->buildForm($form_object, $form_state); + $form = \Drupal::formBuilder()->buildForm('\Drupal\views\Form\ViewsExposedForm', $form_state); if (!$this->view->display_handler->displaysExposed() || (!$block && $this->view->display_handler->getOption('exposed_block'))) { return array(); diff --git a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php index 9943f67..6ce61e1 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php @@ -654,15 +654,23 @@ public function providerTestGetError() { public function testGetCache() { $form_id = 'test_form_id'; $expected_form = $form_id(); + $expected_form['#token'] = FALSE; - // FormBuilder::buildForm() will be called 3 times, but the form object will - // only be called twice due to caching. - $form_arg = $this->getMockForm(NULL, $expected_form, 2); + // FormBuilder::buildForm() will be called twice, but the form object will + // only be called once due to caching. + $form_arg = $this->getMockForm(NULL, $expected_form, 1); - // The CSRF token and the user authentication are checked each time. - $this->csrfToken->expects($this->exactly(3)) + // The CSRF token is checked each time. + $this->csrfToken->expects($this->exactly(2)) ->method('get') ->will($this->returnValue('csrf_token')); + // The CSRF token is validated only when retrieving from the cache. + $this->csrfToken->expects($this->once()) + ->method('validate') + ->with('csrf_token') + ->will($this->returnValue(TRUE)); + // The user is checked for authentication once for the form building and + // twice for each cache set. $this->account->expects($this->exactly(3)) ->method('isAuthenticated') ->will($this->returnValue(TRUE)); @@ -670,36 +678,30 @@ public function testGetCache() { // Do an initial build of the form and track the build ID. $form_state = array(); $form_state['build_info']['callback_object'] = $form_arg; - $form_state['build_info']['args'] = array(); $form_state['build_info']['files'] = array(array('module' => 'node', 'type' => 'pages.inc')); $form_state['cache'] = TRUE; $form = $this->formBuilder->buildForm($form_id, $form_state); - // Rebuild the form, this time setting it up to be cached. - $form_state['rebuild'] = TRUE; - $form_state['rebuild_info']['copy']['#build_id'] = TRUE; - $form_state['input']['form_token'] = $form['#token']; - $form_state['input']['form_id'] = $form_id; - $form_state['input']['form_build_id'] = $form['#build_id']; - $form = $this->formBuilder->buildForm($form_id, $form_state); - $cached_form = $form; $cached_form['#cache_token'] = 'csrf_token'; // The form cache, form_state cache, and CSRF token validation will only be // called on the cached form. $this->formCache->expects($this->once()) + ->method('setWithExpire'); + $this->formCache->expects($this->once()) ->method('get') ->will($this->returnValue($cached_form)); $this->formStateCache->expects($this->once()) ->method('get') ->will($this->returnValue($form_state)); - $this->csrfToken->expects($this->once()) - ->method('validate') - ->will($this->returnValue(TRUE)); // The final form build will not trigger any actual form building, but will // use the form cache. + $form_state['input']['form_id'] = $form_id; + $form_state['input']['form_build_id'] = $form['#build_id']; $this->formBuilder->buildForm($form_id, $form_state); + $errors = $this->formBuilder->getErrors($form_state); + $this->assertEmpty($errors); } /**