pantheon-systems/smart_content_cdn

此软件包已被弃用且不再维护。未建议替代软件包。

在 Pantheon 平台上为 Drupal 提供边缘集成。

安装: 411

依赖项: 0

建议者: 1

安全: 0

星级: 4

关注者: 12

分支: 2

开放问题: 3

类型:drupal-module

1.0.0 2022-09-09 21:06 UTC

README

已迁移到 Drupal.org Smart Content CDN

Unsupported Build Status Package Version

扩展 smart_content 的 Drupal 模块,支持 Pantheon Edge Integrations 和个性化功能。

安装

我们建议使用 Composer 安装此模块。在项目根目录中运行

composer require pantheon-systems/smart_content_cdn

这将安装 Smart Content 模块、Smart Content CDN 和 pantheon-systems/pantheon-edge-integrations -- 这是一个 PHP 库,是 Smart Content CDN 所必需的。没有 pantheon-edge-integrations 库,Smart Content CDN 将无法正常工作。

有关如何安装和设置 Smart Content CDN 的详细说明,请参阅 Edge Integration Guide

API

您可以在自己的自定义模块中使用 Smart Content CDN 获取头信息。这可以在任何类上下文或过程上下文中的任何钩子中使用。

  1. 使用 use 语句包含库。
    use Pantheon\EI\HeaderData;
  2. 使用以下代码片段获取头数据对象
    // Get header data.
    $smart_content_cdn = new HeaderData();
    $p_obj = $smart_content_cdn->returnPersonalizationObject();

Drupal 事件订阅者 Vary 头

在 Drupal 事件订阅者中设置 Vary 头,可以按用户定制内容。

/**
 * This method is called when the kernel.response is dispatched.
 *
 * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
 *   The dispatched event.
 */
public function onRespond(FilterResponseEvent $event) {
  $config = \Drupal::configFactory()->get('smart_content_cdn.config');

  // Check if Vary Header should be set.
  if ($config->get('set_vary') ?? TRUE) {
    $response = $event->getResponse();

    // Header keys to add to Vary header.
    $vary_headers = ['Audience', 'Interest', 'Role'];

    // Retrieve and set vary header.
    $smart_content_cdn = new HeaderData();
    $response_vary_header = $smart_content_cdn->returnVaryHeader($vary_headers);
    $response->headers->add($response_vary_header);
  }
}

集成

有几种不同的方法可以扩展 Smart Content CDN 模块的功能。

智能内容预览

使用 智能内容预览 允许预览您已设置的各个部分。

智能内容 SSR

智能内容 SSR 模块基于 Smart Content 模块提供的 Decision block 添加了一个服务器端渲染 Decision block。如果您想提高网站速度并保持一致性,请使用此模块。

测试 & Linting

此模块通过 PHPUnit 测试和 PHP_CodeSniffer Linting 通过 Drupal Coder 软件包运行。

可以使用 Composer 的 composer test:unit 命令运行 PHPUnit 测试。可以通过相同的 test: 前缀添加更多测试并将其添加到 composer test 命令中。

PHPCS代码检查可以使用Composer通过composer lint:php命令执行。可以使用phpcbf命令通过执行composer lint:phpcbf来自动修复代码检查错误。可以通过相同的lint:前缀添加额外的代码检查(例如ESLint),并将其添加到composer lint命令中。