diff --git a/core/lib/Drupal/Core/Form/FormState.php b/core/lib/Drupal/Core/Form/FormState.php index 3524ed8..8e6f13a 100644 --- a/core/lib/Drupal/Core/Form/FormState.php +++ b/core/lib/Drupal/Core/Form/FormState.php @@ -475,8 +475,10 @@ public function getButtons() { * {@inheritdoc} */ public function setCached($cache = TRUE) { - if ($this->isMethodType('GET')) { - throw new \LogicException('NOPE'); + // We try to determine whether this is the initial load of the form. + // For normal forms it is enough + if ($this->isMethodType('GET') && !$this->isSubmitted()) { + throw new \LogicException('Initial form rendering is not allowed to cache the form.'); } $this->cache = (bool) $cache; return $this; diff --git a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php index 985d355..3eca4cc 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php @@ -475,7 +475,7 @@ public function testSetCachedPost() { $form_state = new FormState(); $form_state->setMethod('POST'); $form_state->setCached(); - $this->assertSame(TRUE, $form_state->isCached()); + $this->assertTrue($form_state->isCached()); } /** @@ -487,7 +487,19 @@ public function testSetCachedGet() { $form_state = new FormState(); $form_state->setMethod('GET'); $form_state->setCached(); - $this->assertSame(TRUE, $form_state->isCached()); + } + + /** + * @covers ::setCached + */ + public function testSetCachedGetWithSubmission() { + $form_state = new FormState(); + $form_state->setMethod('GET'); + $form_state->setSubmitted(); + $form_state->setCached(); + + // Get form submissions should not be cached. + $this->assertFalse($form_state->isCached()); } /**