basilicom/pimcore-path-formatter-bundle

此捆绑包为多关系中的 Pimcore DataObjects 提供路径格式化模式配置。

v3.0.0 2024-07-12 07:13 UTC

This package is auto-updated.

Last update: 2024-09-12 07:52:34 UTC


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);
}

配置

  1. basilicom_path_formatter 键添加到您的 Pimcore app/config/config.yml

  2. 通过添加完全限定的数据对象类名作为键,模式字符串作为值来配置模式。
    使用大括号包围的公共获取方法可访问的类属性名称。
    这还使您能够引用基本的 Pimcore Concrete/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})" 
    

    注意:如果属性不存在获取器,占位符将保持不变。

  3. @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