Mercurial > hg > isophonics-drupal-site
diff core/modules/node/src/PageCache/DenyNodePreview.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/node/src/PageCache/DenyNodePreview.php Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,44 @@ +<?php + +namespace Drupal\node\PageCache; + +use Drupal\Core\PageCache\ResponsePolicyInterface; +use Drupal\Core\Routing\RouteMatchInterface; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; + +/** + * Cache policy for node preview page. + * + * This policy rule denies caching of responses generated by the + * entity.node.preview route. + */ +class DenyNodePreview implements ResponsePolicyInterface { + + /** + * The current route match. + * + * @var \Drupal\Core\Routing\RouteMatchInterface + */ + protected $routeMatch; + + /** + * Constructs a deny node preview page cache policy. + * + * @param \Drupal\Core\Routing\RouteMatchInterface $route_match + * The current route match. + */ + public function __construct(RouteMatchInterface $route_match) { + $this->routeMatch = $route_match; + } + + /** + * {@inheritdoc} + */ + public function check(Response $response, Request $request) { + if ($this->routeMatch->getRouteName() === 'entity.node.preview') { + return static::DENY; + } + } + +}