arch-8.x-1.x-dev/modules/product/src/PageCache/DenyProductPreview.php

modules/product/src/PageCache/DenyProductPreview.php
<?php

namespace Drupal\arch_product\PageCache;

use Drupal\Core\PageCache\ResponsePolicyInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
 * Cache policy for product preview page.
 *
 * This policy rule denies caching of responses generated by the
 * entity.product.preview route.
 */
class DenyProductPreview implements ResponsePolicyInterface {

  /**
   * The current route match.
   *
   * @var \Drupal\Core\Routing\RouteMatchInterface
   */
  protected $routeMatch;

  /**
   * Constructs a deny product 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.product.preview') {
      return static::DENY;
    }
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc