heimrichhannot / contao-reader-bundle
此包提供了一个通用的阅读器模块,可用于任意contao实体,并包含标准阅读器特定功能,如字段输出、图片和自动项目处理。
Requires
- php: ^7.4 || ^8.0
- contao/core-bundle: ^4.9
- doctrine/dbal: ^2.10 || ^3.0
- heimrichhannot/contao-be_explanation-bundle: ^2.2
- heimrichhannot/contao-config-element-type-bundle: ^0.2
- heimrichhannot/contao-entity-filter-bundle: ^1.0
- heimrichhannot/contao-filter-bundle: ^1.0
- heimrichhannot/contao-request-bundle: ^1.3
- heimrichhannot/contao-status_messages: ^1.0|^2.0
- heimrichhannot/contao-twig-support-bundle: ^0.2|^1.0
- heimrichhannot/contao-utils-bundle: ^2.206
- symfony/config: ^4.4||^5.4
- symfony/console: ^4.4||^5.4
- symfony/dependency-injection: ^4.4||^5.4
- symfony/event-dispatcher: ^4.4||^5.4
- symfony/event-dispatcher-contracts: ^1.0 || ^2.0 || ^3.0
- symfony/filesystem: ^4.4||^5.4
- symfony/http-foundation: ^4.4||^5.4
- symfony/http-kernel: ^4.4||^5.4
- symfony/polyfill-php80: ^v1.26.0
- symfony/routing: ^4.4||^5.4
- symfony/service-contracts: ^1.0 || ^2.0 || ^3.0
- symfony/translation: ^4.4||^5.4
- symfony/translation-contracts: ^1.1.6||^2||^3
Requires (Dev)
- contao/manager-plugin: ^2.0
- contao/test-case: 1.1.*
- friendsofphp/php-cs-fixer: ^2.2
- php-http/guzzle6-adapter: ^1.1
- php-http/message-factory: ^1.0.2
- phpunit/php-token-stream: ^1.4|^2.0|^3.0
- phpunit/phpunit: ^6.5
- phpunit/phpunit-mock-objects: ^4.0|^5.0
- satooshi/php-coveralls: ^2.0
- symfony/phpunit-bridge: ^3.2
Suggests
- heimrichhannot/contao-list-bundle: Offers a generic list module.
Conflicts
- heimrichhannot/contao-head-bundle: <1.10.0
- heimrichhannot/contao-list-bundle: <1.51.0
- dev-master
- 1.42.3
- 1.42.2
- 1.42.1
- 1.42.0
- 1.41.4
- 1.41.3
- 1.41.2
- 1.41.1
- 1.41.0
- 1.40.1
- 1.40.0
- 1.39.5
- 1.39.4
- 1.39.3
- 1.39.2
- 1.39.1
- 1.39.0
- 1.38.3
- 1.38.2
- 1.38.1
- 1.38.0
- 1.37.0
- 1.36.2
- 1.36.1
- 1.36.0
- 1.35.1
- 1.35.0
- 1.34.0
- 1.33.2
- 1.33.1
- 1.33.0
- v1.32.x-dev
- 1.32.1
- 1.32.0
- 1.31.1
- 1.31.0
- 1.30.4
- 1.30.3
- 1.30.2
- 1.30.1
- 1.30.0
- 1.29.1
- 1.29.0
- 1.28.0
- 1.27.2
- 1.27.1
- 1.27.0
- 1.26.1
- 1.26.0
- 1.25.1
- 1.25.0
- 1.24.0
- 1.23.8
- 1.23.7
- 1.23.6
- 1.23.5
- 1.23.4
- 1.23.2
- 1.23.1
- 1.23.0
- 1.22.0
- 1.21.0
- 1.20.2
- 1.20.1
- 1.20.0
- 1.19.1
- 1.19.0
- 1.18.0
- 1.16.0
- 1.15.2
- 1.15.1
- 1.15.0
- 1.14.0
- 1.13.0
- 1.12.1
- 1.12.0
- 1.11.2
- 1.11.1
- 1.11.0
- 1.10.1
- 1.10.0
- 1.9.0
- 1.8.7
- 1.8.6
- 1.8.5
- 1.8.4
- 1.8.3
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7.0
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.0
- 1.0.0-beta90
- 1.0.0-beta89
- 1.0.0-beta88
- 1.0.0-beta87
- 1.0.0-beta86
- 1.0.0-beta85
- 1.0.0-beta84
- 1.0.0-beta83
- 1.0.0-beta82
- 1.0.0-beta81
- 1.0.0-beta80
- 1.0.0-beta79
- 1.0.0-beta78
- 1.0.0-beta77
- 1.0.0-beta76
- 1.0.0-beta75
- 1.0.0-beta74
- 1.0.0-beta73
- 1.0.0-beta72
- 1.0.0-beta71
- 1.0.0-beta70
- 1.0.0-beta69
- 1.0.0-beta68
- 1.0.0-beta67
- 1.0.0-beta66
- 1.0.0-beta65
- 1.0.0-beta64
- 1.0.0-beta63
- 1.0.0-beta62
- 1.0.0-beta61
- 1.0.0-beta60
- 1.0.0-beta59
- 1.0.0-beta58
- 1.0.0-beta57
- 1.0.0-beta56
- 1.0.0-beta55
- 1.0.0-beta54
- 1.0.0-beta53
- 1.0.0-beta52
- 1.0.0-beta51
- 1.0.0-beta50
- 1.0.0-beta49
- 1.0.0-beta48
- 1.0.0-beta47
- 1.0.0-beta46
- 1.0.0-beta45
- 1.0.0-beta44
- 1.0.0-beta43
- 1.0.0-beta42
- 1.0.0-beta41
- 1.0.0-beta40
- 1.0.0-beta39
- 1.0.0-beta38
- 1.0.0-beta37
- 1.0.0-beta36
- 1.0.0-beta35
- 1.0.0-beta34
- 1.0.0-beta33
- 1.0.0-beta32
- 1.0.0-beta31
- 1.0.0-beta30
- 1.0.0-beta29
- 1.0.0-beta28
- 1.0.0-beta27
- 1.0.0-beta26
- 1.0.0-beta25
- 1.0.0-beta24
- 1.0.0-beta23
- 1.0.0-beta22
- 1.0.0-beta21
- 1.0.0-beta20
- 1.0.0-beta19
- 1.0.0-beta18
- 1.0.0-beta17
- 1.0.0-beta16
- 1.0.0-beta15
- 1.0.0-beta14
- 1.0.0-beta13
- 1.0.0-beta12
- 1.0.0-beta11
- 1.0.0-beta10
- 1.0.0-beta9
- 1.0.0-beta8
- 1.0.0-beta7
- 1.0.0-beta6
- 1.0.0-beta5
- 1.0.0-beta4
- 1.0.0-beta3
- 1.0.0-beta2
- 1.0.0-beta
- dev-feature/update_head_bundle_integration
- dev-fix-comment-type
- dev-dev
This package is auto-updated.
Last update: 2024-09-07 10:19:27 UTC
README
此包提供了一个通用的阅读器模块,可用于任意contao实体,并包含标准阅读器特定功能,如字段输出、图片和自动项目处理。
这使得除了事件、新闻或常见问题之外,还可以为每个DCA生成阅读器。
功能
- 通用阅读器模块:输出任意DCA实体的实体
- 专用且可继承的阅读器配置实体,可以分配给一个或多个模块
- 支持模板的twig
- Head Bundle 支持
提示:此模块可以与 heimrichhannot/contao-list-bundle 一起使用,后者可以显示任意DCA实体的列表
印象
阅读器配置
概念
可继承的阅读器配置
由于有时读者配置可能会包含大量数据,我们决定将其外包到专用的DCA实体中。这些实体可以以可重用的方式分配给一个或多个阅读器模块。
此外,还可以创建继承自其他读者配置的读者配置。因此,在保持其他一切不变的情况下,可以覆盖单个选项。
项目类
在阅读器中输出的每个数据库记录(例如事件)都由 Item
类建模和包装。具体类是 DefaultItem
。您可以将项目想象为一种ORM(对象关系映射)。
项目最重要的属性是 raw
和 formatted
数组,这些数组也可以在阅读器项目模板中迭代
raw
:包含原始数据库值formatted
:包含原始值的格式化表示
示例:假设一个数据库记录有一个字段 startDate
,它包含在后台选择日期的Unix时间戳。那么 raw
包含这个Unix时间戳,而 formatted
包含根据contao设置中设置的 dateFormat
美化打印的日期,即 "2020-09-12"。
阅读器包使用 heimrichhannot/contao-utils-bundle 中的 FormUtil::prepareSpecialValueForOutput()
方法来处理特殊值。它支持广泛的特殊值类型
- 日期/时间字段
- 数组
- 具有
options
、options_callback
和 DCA 的reference
键中的条目的字段 - 二进制字段(文件、图像等)
- ...
您可以在您的阅读器项目twig模板中以通常的方式访问这两个数组
{% for field, value in raw %} {% endfor %} {% for field, value in formatted %} {% endfor %}
注意:默认情况下,数据库记录的所有值都进行了格式化并可在项目模板中访问。如您所想,如果某些字段有数千个选项,则格式化过程可能需要一些时间,并可能降低您网站的性能。因此,您始终应限制格式化字段,并且仅格式化您真正需要的字段。您可以在阅读器配置(字段 limitFormattedFields
)中调整此设置。
为了方便起见,您还可以在您的twig模板中像这样访问字段值
{{ fieldname }}
如果您配置了字段 fieldname
以进行格式化,则它将包含格式化值。如果没有,则包含原始值。如果它已格式化,您还可以使用以下方式访问其原始值
{{ raw.fieldname }}
阅读器配置元素
每个读者配置可以包含一个或多个读者配置元素。这些元素旨在指定可能多次发生的事情(例如,因为存在许多同一类型的字段)。
当前内置的读者配置元素类型
其他包也可以添加读者配置元素。以下是一些示例
图像
您可以将图像作为格式化值添加,如果您还希望具有图像大小处理或未设置图像时的自动占位符等附加功能,您可以使用图像读取配置元素。
配置完成后,您可以在项目模板中按如下方式输出
{% if images|default and images.myImage|default %} {{ include('@HeimrichHannotContaoUtils/image.html.twig', images.myImage) }} {% endif %}
重要:请注意,默认情况下,生成的图像元素被添加到名为images
的数组中。如果您的DCA包含具有相同名称的字段,您需要指定不同的容器名称,例如resizedImages
(使用overrideTemplateContainerVariable
)。
模板
定义模板有两种方式。
1. 通过前缀
第一种方式是在任何templates
或包的views
目录中简单地部署twig模板,以下为前缀
reader_item_
item_
news_
event_
可以定义更多前缀,请参见第二种方式。
2. 通过config.yml
第二种方式是扩展config.yml
并定义一个严格的模板
Plugin.php
<?php
class Plugin implements BundlePluginInterface, ExtensionPluginInterface
{
/**
* {@inheritdoc}
*/
public function getBundles(ParserInterface $parser)
{
…
}
/**
* {@inheritdoc}
*/
public function getExtensionConfig($extensionName, array $extensionConfigs, ContainerBuilder $container)
{
return ContainerUtil::mergeConfigFile(
'huh_reader',
$extensionName,
$extensionConfigs,
__DIR__ .'/../Resources/config/config.yml'
);
}
}
config.yml
huh:
reader:
templates:
item:
- { name: default, template: "@HeimrichHannotContaoReader/reader_item_default.html.twig" }
item_prefixes:
- reader_item_
- item_
- news_
- event_
开发者
事件
阅读器配置元素
添加新的读者配置元素很容易。
-
创建一个实现了
HeimrichHannot\ConfigElementTypeBundle\ConfigElementType\ConfigElementTypeInterface
的类 -
将类作为具有服务标签
huh.reader.config_element_type
的服务进行注册 -
将友好的类型名称(翻译)添加到
$GLOBALS['TL_LANG']['tl_reader_config_element']['reference']
变量中$lang['reference'][\HeimrichHannot\ReaderBundle\ConfigElementType\CommentConfigElementType::getType()] = 'Comment';