jeyroik/extas-fields-defaults

此包的最新版本(0.2.1)没有可用的许可证信息。

Extas默认字段值

0.2.1 2020-05-26 03:57 UTC

This package is auto-updated.

Last update: 2024-09-26 13:35:28 UTC


README

PHP Composer codecov.io PHPStan Enabled

描述

此包允许为兼容IItem类字段的默认值进行定义。

应用

定义必填字段

使用extas-fields包来定义默认值。

extas.json

{
  "fields": [
    {
      "name": "my_field",
      "title": "My field",
      "description": "Example of usage",
      "type": "string",
      "value": "my value",
      "parameters": {
        "subject": {
          "name": "subject",
          "value": "my.subject"
        }
      }
    }
  ]
}

字段value的值即为该字段的默认值。

接下来需要连接当前包的插件到所需实体。

注意:如果您使用其他插件,例如检查字段值等,建议为当前插件设置更高的优先级,以确保它比其他插件先执行。

extas.json

{
  "plugins": [
    {
      "class": "extas\\components\\plugins\\PluginFieldsDefaults",
      "stage": ["my.subject.init"],
      "priority": 1
    }
  ]
}

安装字段和插件

# vendor/bin/extas i

使用

$my = new class extends Item {
    protected function getSubjectForExtension(): string
    {
        return 'my.subject';
    }
};

echo $my['my_field']; // "my value"