DenyNodePreview.php

Same filename in other branches
  1. 9 core/modules/node/src/PageCache/DenyNodePreview.php
  2. 8.9.x core/modules/node/src/PageCache/DenyNodePreview.php
  3. 10 core/modules/node/src/PageCache/DenyNodePreview.php

Namespace

Drupal\node\PageCache

File

core/modules/node/src/PageCache/DenyNodePreview.php

View source
<?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;
        }
    }

}

Classes

Title Deprecated Summary
DenyNodePreview Cache policy for node preview page.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.