bdunogier/ezplatform-query-fieldtype

此包已被 弃用 并不再维护。作者建议使用 ezsystems/ezplatform-query-fieldtype 包。

定义查询的 eZ Platform 字段类型。

v0.2 2019-04-01 16:43 UTC

README

此字段类型将允许内容管理员将可执行存储库查询映射到字段。

示例用例

  • a place.nearby_places 字段,该字段返回距离当前内容小于 X 千米的地点项,基于其自己的 location 字段
  • a gallery.images 字段,该字段返回是当前画廊项目主要位置的子项的图像项

目的是将控制器和模板中实现的内容和结构逻辑移动到存储库本身。

安装

将包添加到需求

composer require ezsystems/ezplatform-query-fieldtype:^1.0@dev

将包添加到 app/AppKernel.php

$bundles = [
  // ...
  new EzSystems\EzPlatformQueryFieldType\Symfony\EzSystemsEzPlatformQueryFieldTypeBundle(),
];

将包路由添加到 config/routing.yaml

ezplatform.query_fieldtype.routes:
    resource: '@EzSystemsEzPlatformQueryFieldTypeBundle/Resources/config/routing/'
    type: directory

使用

将内容查询字段添加到内容类型。

在字段定义设置中,从列表中选择一个查询类型,以及该字段返回的内容类型。

参数用于在运行时构建查询。它们可以是静态的,也可以映射到字段值所属的内容属性。语法是 YAML,其中键是查询类型参数的名称,值是一个标量,或一个 表达式

以下变量可用于表达式

  • string returnedType: 之前选定的内容类型的标识符
  • eZ\Publish\API\Values\Content\Content content: 当前内容项,也提供对字段值的访问。例如,对于 ezurl 字段:@=content.getFieldValue('url').link
  • eZ\Publish\API\Values\Content\ContentInfo contentInfo: 当前内容项的内容信息
  • eZ\Publish\API\Values\Content\Location mainLocation: 当前内容项的主要位置

一个简单的示例,对于一个期望

  • parent_location_id: 获取子项的位置的 ID
  • content_types: 内容类型标识符或要过滤的标识符数组
parent_location_id: "@=mainLocation.id"
content_types: "@=returnedType"

查看 examples 目录以获取完整示例。