bywatersolutions/silverstripe-jsoneditorfield

Silverstripe JSON Editor Field

0.2.0 2019-12-11 19:01 UTC

This package is auto-updated.

Last update: 2024-09-09 04:22:09 UTC


README

为 Silverstripe 添加基于 JSON Schema 的编辑器。使用 JSON Editor 构建一个交互式表单,用于创建符合提供的 schema 的有效 JSON。

安装

composer require bywatersolutions/silverstripe-jsoneditorfield

使用

use ByWaterSolutions\JsonEditorField\JsonEditorField;

...

private static $db = array[
    'MyJson' => 'Text'
];

public function getCMSFields() {
    $fields = parent::getCMSFields();
    $schema = file_get_contents("path/to/your/schema.json");
    $fields->addFieldToTab("Root.Main", new JsonEditorField("MyJson", "My JSON Document", $this->MyJson, null, $schema));
    return $fields;
}

非常简单!当然,你仍然需要编写 JSON Schema 并确保其有效性……如果你的表单不符合预期,请在浏览器控制台进行检查。