pantheon-systems / smart_content_cdn
在 Pantheon 平台上为 Drupal 提供边缘集成。
Requires
- drupal/smart_content: ^3.0
- pantheon-systems/pantheon-edge-integrations: ^1.1.0
Requires (Dev)
- drupal/coder: ^8.3
- phpunit/phpunit: ^9.5
Suggests
- drupal/smart_content_preview: Smart Content Preview is an optional package that allows you to preview your personalized content. It can be used with Smart Content CDN or with any Smart Content implementation.
- drupal/smart_content_ssr: Smart Content SSR is an optional package that adds a server-side rendered Decision Block. It can be used with Smart Content CDN or with any Smart Content implementation with adjustments.
This package is auto-updated.
Last update: 2023-06-17 17:13:44 UTC
README
已迁移到 Drupal.org Smart Content CDN。
扩展 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 获取头信息。这可以在任何类上下文或过程上下文中的任何钩子中使用。
- 使用
use
语句包含库。use Pantheon\EI\HeaderData;
- 使用以下代码片段获取头数据对象
// 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
命令中。