contextualcode/utility-bundle

eZ Publish 扩展包,用于存放工具。

安装次数: 6,893

依赖者: 0

建议者: 0

安全性: 0

星标: 0

分支: 1

类型:symfony-bundle

v4.1.1 2024-08-16 08:28 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.ymlezpublish/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'
   }) 
%}

这将返回一个数组,每个值都包含 locationcontent 键。

另一个示例,使用 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 参数

必需

  • parentLocationIDparentLocation
    • 从开始搜索的父位置节点 ID 或实际位置。

可选

  • loadContent
    • 是否加载并返回每个项的 content 键的内容。
    • 类型: bool
    • 默认: false
  • ignoreVisibility
    • 是否在搜索时忽略可见性。
    • 类型: bool
    • 默认: false
  • limit
    • 结果数量的限制。
    • 类型: stringintnull
    • 默认: null
  • offset
    • 结果偏移量。
    • 类型: int
    • 默认: 0
  • depth
    • 将结果限制为从 parentLocation 的此深度。
    • depthOperator 配对。
    • 类型: stringarrayintnull
    • 默认: null
  • depthOperator
    • 用于 depth 限制的运算符。
    • 类型: string,一个: 'contains', 'between''eq''gt''gte''in''lt''lte'
    • 默认: 'eq'
  • priority
    • 将结果限制为此优先级。
    • priorityOperator 配对。
    • 类型: stringarrayintnull
    • 默认: null
  • priorityOperator
    • 用于 priority 限制的运算符。
    • 类型: string,一个: 'between''gt''gte''lt''lte'
    • 默认: 'lte'
  • sectionFilter
    • 将结果限制为单个部分 ID 或部分 ID 数组。
    • sectionFilterOperator 配对。
    • 类型: stringarrayintnull
    • 默认: null
  • sectionFilterOperator
    • 用于 sectionFilter 的运算符。
    • 类型: string,一个: 'or''not'
    • 默认: 'or'
  • classFilter
    • 将结果限制为单个类 ID 或类 ID 数组。
    • classFilterOperator 配对。
    • 类型: stringarrayintnull
    • 默认: null
  • classFilterOperator
    • 用于 classFilter 的运算符。
    • 类型: string,一个: 'or''not'
    • 默认: 'or'
  • attributeFilter
    • 通过属性进行筛选。应为一个数组,其值如下: [ $field_identifier, $operator, $field_value ],其中 $operator 是以下之一: 'between''eq''gt''gte''in''like''lt''lte'
    • 类型: arrayarraynull
    • 默认: 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 中相同索引的值配对。如果 sortClausessortOrders 的长度不同,则使用默认值填充缺失的值。
    • 类型: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)

更多文档即将推出。