core/lib/Drupal/Core/Form/ConfirmFormHelper.php | 5 +++++ core/modules/search/src/Controller/SearchController.php | 1 + .../tests/modules/batch_test/src/Form/BatchTestMultiStepForm.php | 5 +++++ core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php | 5 +++++ 4 files changed, 16 insertions(+) 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/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']); } /**