diff --git a/core/lib/Drupal/Core/Form/FormCache.php b/core/lib/Drupal/Core/Form/FormCache.php index 5c77c30..05c6cf0 100644 --- a/core/lib/Drupal/Core/Form/FormCache.php +++ b/core/lib/Drupal/Core/Form/FormCache.php @@ -72,7 +72,7 @@ class FormCache implements FormCacheInterface { * * @var \Symfony\Component\HttpFoundation\RequestStack */ - protected $request; + protected $requestStack; /** * A policy rule determining the cacheability of a request. @@ -109,7 +109,7 @@ public function __construct(KeyValueExpirableFactoryInterface $key_value_expirab $this->logger = $logger; $this->configFactory = $config_factory; $this->csrfToken = $csrf_token; - $this->request = $request_stack; + $this->requestStack = $request_stack; $this->requestPolicy = $request_policy; } @@ -218,7 +218,7 @@ public function setCache($form_build_id, $form, FormStateInterface $form_state) * Checks if the page is cacheable. */ protected function isPageCacheable($allow_caching = NULL) { - return ($this->requestPolicy->check($this->request) === RequestPolicyInterface::ALLOW); + return ($this->requestPolicy->check($this->requestStack->getCurrentRequest()) === RequestPolicyInterface::ALLOW); } } diff --git a/core/tests/Drupal/Tests/Core/Form/FormCacheTest.php b/core/tests/Drupal/Tests/Core/Form/FormCacheTest.php index f76bbc4..41d76df 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormCacheTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormCacheTest.php @@ -82,6 +82,20 @@ class FormCacheTest extends UnitTestCase { protected $configFactory; /** + * The request stack. + * + * @var \Symfony\Component\HttpFoundation\RequestStack|\PHPUnit_Framework_MockObject_MockObject + */ + protected $requestStack; + + /** + * A policy rule determining the cacheability of a request. + * + * @var \Drupal\Core\PageCache\RequestPolicyInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $requestPolicy; + + /** * {@inheritdoc} */ protected function setUp() { @@ -108,8 +122,11 @@ protected function setUp() { $this->logger = $this->getMock('Psr\Log\LoggerInterface'); $this->configFactory = $this->getConfigFactoryStub(['system.performance' => ['cache.page.use_internal' => FALSE]]); + $this->requestStack = $this->getMock('\Symfony\Component\HttpFoundation\RequestStack'); + $this->requestPolicy = $this->getMock('\Drupal\Core\PageCache\RequestPolicyInterface'); + - $this->formCache = new FormCache($this->keyValueExpirableFactory, $this->moduleHandler, $this->account, $this->csrfToken, $this->logger, $this->configFactory); + $this->formCache = new FormCache($this->keyValueExpirableFactory, $this->moduleHandler, $this->account, $this->csrfToken, $this->logger, $this->configFactory, $this->requestStack, $this->requestPolicy); } /** @@ -495,7 +512,7 @@ public function testSetCacheImmutableForm() { // object with the internal page cache enabled. $this->configFactory = $this->getConfigFactoryStub(['system.performance' => ['cache.page.use_internal' => TRUE]]); $this->formCache = $this->getMockBuilder('Drupal\Core\Form\FormCache') - ->setConstructorArgs([$this->keyValueExpirableFactory, $this->moduleHandler, $this->account, $this->csrfToken, $this->logger, $this->configFactory]) + ->setConstructorArgs([$this->keyValueExpirableFactory, $this->moduleHandler, $this->account, $this->csrfToken, $this->logger, $this->configFactory, $this->requestStack, $this->requestPolicy]) ->setMethods(['isPageCacheable']) ->getMock();