basilicom / path-formatter-bundle
此插件为Pimcore DataObjects的多关系提供了路径格式化模式配置。
Requires
- php: >=8.1
- pimcore/pimcore: >=11
Requires (Dev)
- phpunit/phpunit: ^9.0
README
用例/摘要
如果您想在数据对象在关系字段中列出时显示特定信息,可以使用此插件轻松配置一个显示模式。
无需在项目中创建新的PathFormatter来显示产品类的名称、价格和货币,您可以直接配置如下
# app/config/config.yml
basilicom_path_formatter:
pattern:
Pimcore\Model\DataObject\Product: "{name} {price}{currency}"
或者您可能想为特定类的关系字段中的产品定义一个特定的模式。
# app/config/config.yml
basilicom_path_formatter:
pattern:
Pimcore\Model\DataObject\Product: "{name} {price}{currency}" # global product format
Pimcore\Model\DataObject\ProductList::products:
patternOverwrites:
Pimcore\Model\DataObject\Product: "#{id} {name}"
当产品在所有带有格式化器的关联字段中格式化为Sneakers 19.99EUR
时,ProductList-Class将以#13 - Sneakers
的格式显示它们
版本信息
安装
使用composer require basilicom/pimcore-path-formatter-bundle
安装此插件
执行bin/console pimcore:bundle:enable BasilicomPathFormatterBundle
或者
将以下行添加到AppKernel::registerBundlesToCollection()
(推荐)
if (class_exists('\\Basilicom\\PathFormatterBundle\\BasilicomPathFormatterBundle')) { $collection->addBundle(new \Basilicom\PathFormatterBundle\BasilicomPathFormatterBundle); }
配置
-
将
basilicom_path_formatter
键添加到您的Pimcoreapp/config/config.yml
-
通过添加完全限定的数据对象类名作为键,模式字符串作为值来配置模式。
使用大括号包围的公共getter方法可访问的类属性名称。
这还使您能够引用基本的PimcoreConcrete
/AbstractObject
方法,如fullPath
对应于\Pimcore\Model\DataObject\AbstractObject::getFullPath())
className
对应于\Pimcore\Model\DataObject\AbstractObject::getClassName())
- ...
示例
basilicom_path_formatter: pattern: # output of e.g. "Product: Sneakers (/dataObject/Products/Sneakers)" Pimcore\Model\DataObject\Product: "Product: {name} ({fullPath})"
注意:如果不存在属性的getter,占位符将保持不变。
-
将
@Basilicom\PathFormatterBundle\DependencyInjection\BasilicomPathFormatter
添加到关系字段类型中的格式化器字段。
注意:@
是重要的,因为格式化器被注册为服务,包括依赖注入。
高级配置
上下文模式覆盖
可以配置基于上下文的模式,以便特定类的关系字段中的数据对象将被格式化得不同。
示例
# app/config/config.yml basilicom_path_formatter: pattern: # global product format Pimcore\Model\DataObject\Product: "{name} {price}{currency}" # format-overwrite in the context of a ProductList for the relation-field "products" Pimcore\Model\DataObject\ProductList::products: patternOverwrites: # both classes are extending the Pimcore\Model\DataObject\Product so we still can overwrite the "Product" pattern. Pimcore\Model\DataObject\BasicProduct: "#{id} {name}" Pimcore\Model\DataObject\PremiumProduct: "#{id} {name} (premium-only!)"
虽然产品将在所有关系字段中格式化为Sneakers 19.99EUR
,但ProductList-Class将根据产品类显示为#13 - Sneakers
或#13 - Sneakers (仅限高级!)
。
格式化文档和资产
basilicom_path_formatter: pattern: Pimcore\Model\Asset: "{id} {key}" Pimcore\Model\Document: "{id} {key}" Pimcore\Model\DataObject\Car::files: patternOverwrites: Pimcore\Model\Asset: "{key}" Pimcore\Model\Document: "{key}"
其他功能
在数据对象中切换继承的值
默认情况下将使用数据对象的继承值。为了避免这种情况,只需禁用此配置
basilicom_path_formatter:
enable_inheritance: true|false # default true
显示图片
一旦在模式中引用了属性,该属性是Pimcore\ModelAsset\Image
,它将在关联列表中呈现为小预览。可以通过将enable_asset_preview
的值设置为false
来禁用此功能。
basilicom_path_formatter:
enable_asset_preview: true|false # default true
作者: Alexander Heidrich (Basilicom GmbH)
许可证: GPL v3