oposs/silverstripe-structured-data

创建、管理和验证结构化的yaml/json格式文本数据

安装: 265

依赖: 0

建议者: 0

安全性: 0

星标: 1

关注者: 5

分支: 0

开放问题: 1

类型:silverstripe-vendormodule

0.1.2 2023-03-08 11:08 UTC

This package is auto-updated.

Last update: 2024-09-08 14:21:46 UTC


README

创建、管理和验证结构化的yaml/json格式文本数据,并通过graphQL使其可用

安装

通过composer安装: composer require oposs/silverstripe-structured-data.

要启用graphQL类型,将以下行添加到您的 app/_config/graphql.yml

SilverStripe\GraphQL\Schema\Schema:
  schemas:
    default:
      src:
        - 'oposs/silverstripe-structured-data: _graphql'

如果您只需要一个可以与JSON模式进行验证的表单字段,您可能想要禁用管理后端

Oposs\StructuredData\Extensions\StructuredDataAdmin:
  show_admin_interface: false

权限

此模块提供的全局权限

  • STRUCTURED_DATA_VIEW:查看结构化数据模块和存储的数据和模式的权限
  • STRUCTURED_DATA_ADMIN:拥有此权限的用户可以编辑/创建/删除所有数据和模式

可以通过为每个数据对象单独定义允许的组来实现对编辑访问的细粒度控制。

用法

除了可以通过graphQL访问数据之外,此模块还提供了一个专门的StructuredDataField,可以设置来验证其输入是否与模式匹配

<?php
use Oposs\StructuredData\Form\StructuredDataField;
use Oposs\StructuredData\DataObjects\SchemaObject;
use SilverStripe\Control\Controller;

$SCHEMA_DUMMY = '{}';

TextAreaField::create('schema_field')
    ->setTitle('Schema for yaml_field');
    ->setReadonly(!Permission::check('SOME_SUPER_ADMIN_CAPABILITY'))

StructuredDataField::create('yaml_field')
    // Using a schema object
    ->setValidationSchemaName(SchemaObject::get('name')->first())
    // Using a string
    ->setValidationSchemaName($SCHEMA_DUMMY)
    // And the special case when the schema is configurable in the same form
    ->setValidationSchemaName(Controller::curr()->getRequest()->postVar('schema_field') ?? '{}')
    ->setTitle('Yaml Field');
   

GraphQL示例

{
    "query": "{ readStructuredDatas(filter: {key: {eq: \"test-data\"}}) { nodes {  asJsonBlob   structured_data   }  }}"
}