contextualcode / utility-bundle
eZ Publish 扩展包,用于存放工具。
v4.1.1
2024-08-16 08:28 UTC
Requires
- php: >=7.1
- ezsystems/ezplatform-http-cache: ^2.0
- ezsystems/ezplatform-kernel: ^1.0
This package is not auto-updated.
Last update: 2024-09-27 13:01:55 UTC
README
这是一个用于存放工具的 eZ Publish 5 Symfony 扩展包。
安装
运行 composer require
$ composer require contextualcode/utility-bundle
在 app/AppKernel.php
(ezpublish/EzPublishKernel.php
) 的 registerBundles
方法中添加此行以启用扩展包
public function registerBundles()
{
$bundles = array(
...
new ContextualCode\UtilityBundle\ContextualCodeUtilityBundle(),
...
);
在 app/config/config.yml
或 ezpublish/config/config.yml
中将 UtilityService 添加为 Twig 全局变量
twig:
globals:
cc_utilities: "@contextualcode.utility.utilityservice"
使用方法
此扩展包提供了许多不同的工具函数。
fetch
从 Twig 模板中调用 fetch
的快速示例,以获取当前节点的所有横幅对象
{% set banners = cc_utilities.fetch({
'parentLocation': location,
'classFilter': 'banner',
'depth': 1,
'loadContent': true,
'sortClause': 'priority',
'sortOrder': 'desc'
})
%}
这将返回一个数组,每个值都包含 location
和 content
键。
另一个示例,使用 persistent
属性选中,从当前节点向上获取最近的 alert
项目,按优先级排序,然后按名称排序
{% set paths = location.pathString|split('/')|reverse %}
{% set found_alert = false %}
{% for locationID in paths if not found_alert and locationID %}
{% set alert = cc_utilities.fetch({
'parentLocationID': locationID,
'classFilter': 'alert',
'sortClauses': [ 'priority', 'name' ],
'sortOrders': [ 'desc', 'desc' ],
'loadContent': true,
'depth': 1,
'limit': 1,
'attributeFilter': [
[ 'persistent', 'eq', true ]
]
})
%}
{% set found_alert = alert|length > 0 %}
{% endfor %}
fetch
参数
必需
parentLocationID
或parentLocation
- 从开始搜索的父位置节点 ID 或实际位置。
可选
loadContent
- 是否加载并返回每个项的
content
键的内容。 - 类型:
bool
- 默认:
false
- 是否加载并返回每个项的
ignoreVisibility
- 是否在搜索时忽略可见性。
- 类型:
bool
- 默认:
false
limit
- 结果数量的限制。
- 类型:
string
或int
或null
- 默认:
null
offset
- 结果偏移量。
- 类型:
int
- 默认:
0
depth
- 将结果限制为从
parentLocation
的此深度。 - 与
depthOperator
配对。 - 类型:
string
或array
或int
或null
- 默认:
null
- 将结果限制为从
depthOperator
- 用于
depth
限制的运算符。 - 类型:
string
,一个:'contains', 'between'
,'eq'
,'gt'
,'gte'
,'in'
,'lt'
,'lte'
- 默认:
'eq'
- 用于
priority
- 将结果限制为此优先级。
- 与
priorityOperator
配对。 - 类型:
string
或array
或int
或null
- 默认:
null
priorityOperator
- 用于
priority
限制的运算符。 - 类型:
string
,一个:'between'
,'gt'
,'gte'
,'lt'
,'lte'
- 默认:
'lte'
- 用于
sectionFilter
- 将结果限制为单个部分 ID 或部分 ID 数组。
- 与
sectionFilterOperator
配对。 - 类型:
string
或array
或int
或null
- 默认:
null
sectionFilterOperator
- 用于
sectionFilter
的运算符。 - 类型:
string
,一个:'or'
,'not'
- 默认:
'or'
- 用于
classFilter
- 将结果限制为单个类 ID 或类 ID 数组。
- 与
classFilterOperator
配对。 - 类型:
string
或array
或int
或null
- 默认:
null
classFilterOperator
- 用于
classFilter
的运算符。 - 类型:
string
,一个:'or'
,'not'
- 默认:
'or'
- 用于
attributeFilter
- 通过属性进行筛选。应为一个数组,其值如下:
[ $field_identifier, $operator, $field_value ]
,其中$operator
是以下之一:'between'
,'eq'
,'gt'
,'gte'
,'in'
,'like'
,'lt'
,'lte'
- 类型:
array
的array
或null
- 默认:
null
- 通过属性进行筛选。应为一个数组,其值如下:
attributeFilterOperator
- 用于
attributeFilter
的运算符。 - 类型:
string
,一个:'and'
,'or'
,'not'
- 默认:
'and'
- 用于
sortClause
- 使用单个排序子句。如果您想指定多个排序子句,请使用
sortClauses
。 - 与
sortOrder
配对。 - 类型:
null
(使用父位置排序子句),或string
,以下之一:'path'
、'published'
、'modified'
、'section'
、'depth'
、'priority'
、'name'
、'contentobject_id'
- 默认:
null
(使用父位置排序子句)
- 使用单个排序子句。如果您想指定多个排序子句,请使用
sortOrder
- 使用单个排序顺序。
- 与
sortClause
配对。 - 类型:
null
(使用父位置排序顺序),或string
,以下之一:'asc'
、'desc'
- 默认:
null
(使用父位置排序顺序)
sortClauses
- 与
sortClause
相同,但可以作为一个数组传递多个(用于次要、三级等排序)。 - 与
sortOrders
配对。 - 类型:
array
,包含对sortClause
的有效值。 - 默认:
array(null)
- 与
sortOrders
- 与
sortOrder
相同,但可以作为一个数组传递多个(用于次要、三级等排序)。 - 每个都将与
sortClauses
中相同索引的值配对。如果sortClauses
和sortOrders
的长度不同,则使用默认值填充缺失的值。 - 类型:
array
,包含对sortOrders
的有效值。 - 默认:
array(null)
- 与
getContent($contentID, $lang = 'eng-US')
getContentFromLocationID($locationID, $lang = 'eng-US')
getContentFromLocation($location, $lang = 'eng-US')
getContentInfo($contentID, $lang = 'eng-US')
getParentLocationFromLocation($location)
getParentLocationIDFromLocation($location)
getParentLocationIDFromLocationID($locationID)
getParentLocationIDFromLocationID($locationID)
getParentLocationIDFromLocationID($locationID)
getMainLocationIDFromContentID($contentID)
getContentFromRelationAttribute($content, $attributeID, $lang = 'eng-US')
如果传递了对象关系属性的 $attributeID
,则返回内容。如果传递了对象关系属性的 $attributeID
,则返回内容数组。
getContentInfoFromRelationAttribute($content, $attributeID, $lang = 'eng-US')
如果传递了对象关系属性的 $attributeID
,则返回内容信息。如果传递了对象关系属性的 $attributeID
,则返回内容信息数组。
getAttributeID($content, $attributeID)
getFileAttributeFileName($content, $attributeID)
getContentDownloadURL($content, $attributeID)
更多文档即将推出。