core/lib/Drupal/Core/Form/ConfirmFormHelper.php | 5 +++++ core/lib/Drupal/Core/Form/FormBuilder.php | 5 ----- .../block/src/Tests/Views/DisplayBlockTest.php | 10 ++++------ .../search/src/Controller/SearchController.php | 1 + .../batch_test/src/Form/BatchTestMultiStepForm.php | 5 +++++ .../Drupal/Tests/Core/Form/ConfirmFormHelperTest.php | 5 +++++ core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php | 19 +++++-------------- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/core/lib/Drupal/Core/Form/ConfirmFormHelper.php b/core/lib/Drupal/Core/Form/ConfirmFormHelper.php index fab63f9..5446a3d 100644 --- a/core/lib/Drupal/Core/Form/ConfirmFormHelper.php +++ b/core/lib/Drupal/Core/Form/ConfirmFormHelper.php @@ -52,6 +52,11 @@ public static function buildCancelLink(ConfirmFormInterface $form, Request $requ '#title' => $form->getCancelText(), '#attributes' => ['class' => ['button']], '#url' => $url, + '#cache' => [ + 'contexts' => [ + 'url.query_args:destination', + ], + ], ]; } diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index 6e64d0c..adf4c86 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -674,11 +674,6 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) { $form['#action'] = $placeholder; } - // If the form method is specified in the form, pass it on to FormState. - if (isset($form['#method'])) { - $form_state->setMethod($form['#method']); - } - // Fix the form method, if it is 'get' in $form_state, but not in $form. if ($form_state->isMethodType('get') && !isset($form['#method'])) { $form['#method'] = 'get'; diff --git a/core/modules/block/src/Tests/Views/DisplayBlockTest.php b/core/modules/block/src/Tests/Views/DisplayBlockTest.php index 80bcde7..9b85831 100644 --- a/core/modules/block/src/Tests/Views/DisplayBlockTest.php +++ b/core/modules/block/src/Tests/Views/DisplayBlockTest.php @@ -8,7 +8,6 @@ namespace Drupal\block\Tests\Views; use Drupal\Component\Serialization\Json; -use Drupal\Core\Url; use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait; use Drupal\views\Entity\View; use Drupal\views\Views; @@ -272,7 +271,6 @@ public function testBlockRendering() { * Tests the various testcases of empty block rendering. */ public function testBlockEmptyRendering() { - $url = new Url('test_page_test.test_page'); // Remove all views_test_data entries. \Drupal::database()->truncate('views_test_data')->execute(); /** @var \Drupal\views\ViewEntityInterface $view */ @@ -287,7 +285,7 @@ public function testBlockEmptyRendering() { $display['display_options']['block_hide_empty'] = TRUE; $view->save(); - $this->drupalGet($url); + $this->drupalGet(''); $this->assertEqual(0, count($this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]'))); // Ensure that the view cachability metadata is propagated even, for an // empty block. @@ -307,7 +305,7 @@ public function testBlockEmptyRendering() { ]; $view->save(); - $this->drupalGet($url); + $this->drupalGet(''); $this->assertEqual(1, count($this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]'))); $this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:system.site', 'config:views.view.test_view_block' ,'rendered'])); $this->assertCacheContexts(['url.path', 'url.query_args', 'user.roles:authenticated']); @@ -325,7 +323,7 @@ public function testBlockEmptyRendering() { ]; $view->save(); - $this->drupalGet($url); + $this->drupalGet(''); $this->assertEqual(0, count($this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]'))); $this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:system.site', 'config:views.view.test_view_block' ,'rendered'])); $this->assertCacheContexts(['url.path', 'url.query_args', 'user.roles:authenticated']); @@ -342,7 +340,7 @@ public function testBlockEmptyRendering() { ]; $view->save(); - $this->drupalGet($url); + $this->drupalGet(''); $this->assertEqual(1, count($this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]'))); $this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:system.site', 'config:views.view.test_view_block' ,'rendered'])); $this->assertCacheContexts(['url.path', 'url.query_args', 'user.roles:authenticated']); diff --git a/core/modules/search/src/Controller/SearchController.php b/core/modules/search/src/Controller/SearchController.php index e775531..4d839d1 100644 --- a/core/modules/search/src/Controller/SearchController.php +++ b/core/modules/search/src/Controller/SearchController.php @@ -75,6 +75,7 @@ public function view(Request $request, SearchPageInterface $entity) { // Build the form first, because it may redirect during the submit, // and we don't want to build the results based on last time's request. + $build['#cache']['contexts'][] = 'url.query_args:keys'; if ($request->query->has('keys')) { $keys = trim($request->get('keys')); $plugin->setSearch($keys, $request->query->all(), $request->attributes->all()); diff --git a/core/modules/system/tests/modules/batch_test/src/Form/BatchTestMultiStepForm.php b/core/modules/system/tests/modules/batch_test/src/Form/BatchTestMultiStepForm.php index 8d40948..90ddb62 100644 --- a/core/modules/system/tests/modules/batch_test/src/Form/BatchTestMultiStepForm.php +++ b/core/modules/system/tests/modules/batch_test/src/Form/BatchTestMultiStepForm.php @@ -40,6 +40,11 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => 'Submit', ); + // This is a POST form with multiple steps that does not transition from one + // step to the next via POST requests, but via GET requests, because it uses + // Batch API to advance through the steps. + $form['#cache']['max-age'] = 0; + return $form; } diff --git a/core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php b/core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php index 1dc65a9..27743cb 100644 --- a/core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php +++ b/core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php @@ -33,6 +33,7 @@ public function testCancelLinkTitle() { $link = ConfirmFormHelper::buildCancelLink($form, new Request()); $this->assertSame($cancel_text, $link['#title']); + $this->assertSame(['contexts' => ['url.query_args:destination']], $link['#cache']); } /** @@ -49,6 +50,7 @@ public function testCancelLinkRoute() { ->will($this->returnValue($cancel_route)); $link = ConfirmFormHelper::buildCancelLink($form, new Request()); $this->assertEquals(Url::fromRoute($route_name), $link['#url']); + $this->assertSame(['contexts' => ['url.query_args:destination']], $link['#cache']); } /** @@ -64,6 +66,7 @@ public function testCancelLinkRouteWithParams() { ->will($this->returnValue($expected)); $link = ConfirmFormHelper::buildCancelLink($form, new Request()); $this->assertEquals($expected, $link['#url']); + $this->assertSame(['contexts' => ['url.query_args:destination']], $link['#cache']); } /** @@ -86,6 +89,7 @@ public function testCancelLinkRouteWithUrl() { ->will($this->returnValue($cancel_route)); $link = ConfirmFormHelper::buildCancelLink($form, new Request()); $this->assertSame($cancel_route, $link['#url']); + $this->assertSame(['contexts' => ['url.query_args:destination']], $link['#cache']); } /** @@ -112,6 +116,7 @@ public function testCancelLinkDestination($destination) { $link = ConfirmFormHelper::buildCancelLink($form, new Request($query)); $this->assertSame($url, $link['#url']); + $this->assertSame(['contexts' => ['url.query_args:destination']], $link['#cache']); } /** diff --git a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php index 790ad86..d95e3bc 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php @@ -773,7 +773,7 @@ public function providerTestInvalidToken() { * * @dataProvider providerTestFormTokenCacheability */ - function testFormTokenCacheability($token, $action, $is_authenticated, $expected_form_cacheability, $expected_token_cacheability) { + function testFormTokenCacheability($token, $is_authenticated, $expected_form_cacheability, $expected_token_cacheability) { $user = $this->prophesize(AccountProxyInterface::class); $user->isAuthenticated() ->willReturn($is_authenticated); @@ -787,10 +787,6 @@ function testFormTokenCacheability($token, $action, $is_authenticated, $expected $form['#token'] = $token; } - if (isset($action)) { - $form['#action'] = $action; - } - $form_arg = $this->getMock('Drupal\Core\Form\FormInterface'); $form_arg->expects($this->once()) ->method('getFormId') @@ -824,15 +820,10 @@ function testFormTokenCacheability($token, $action, $is_authenticated, $expected */ function providerTestFormTokenCacheability() { return [ - '#token:none,#action:something,authenticated:true' => [NULL, '/some/path', TRUE, ['contexts' => ['user.roles:authenticated']], ['max-age' => 0]], - '#token:false,#action:something,authenticated:true' => [FALSE, '/some/path', TRUE, NULL, NULL], - '#token:none,#action:something,authenticated:false' => [NULL, '/some/path', FALSE, ['contexts' => ['user.roles:authenticated']], NULL], - '#token:false,#action:something,authenticated:false' => [FALSE, '/some/path', FALSE, NULL, NULL], - - '#token:none,#action:none,authenticated:true' => [NULL, NULL, TRUE, ['contexts' => ['url.path', 'url.query_args', 'user.roles:authenticated']], ['max-age' => 0]], - '#token:false,#action:none,authenticated:true' => [FALSE, NULL, TRUE, ['contexts' => ['url.path', 'url.query_args']], NULL], - '#token:none,#action:none,authenticated:false' => [NULL, NULL, FALSE, ['contexts' => ['url.path', 'url.query_args', 'user.roles:authenticated']], NULL], - '#token:false,#action:none,authenticated:false' => [FALSE, NULL, FALSE, ['contexts' => ['url.path', 'url.query_args']], NULL], + 'token:none,authenticated:true' => [NULL, TRUE, ['contexts' => ['user.roles:authenticated']], ['max-age' => 0]], + 'token:false,authenticated:true' => [FALSE, TRUE, NULL, NULL], + 'token:none,authenticated:false' => [NULL, FALSE, ['contexts' => ['user.roles:authenticated']], NULL], + 'token:false,authenticated:false' => [FALSE, FALSE, NULL, NULL], ]; }