oposs / silverstripe-structured-data
Create, manage and validate structured yaml/json formatted text data
Installs: 288
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 5
Forks: 0
Open Issues: 1
Type:silverstripe-vendormodule
Requires
- php: ^7.4 || ^8.0
- opis/json-schema: ^2.2
- silverstripe/cms: ^4
- silverstripe/framework: ^4
- silverstripe/graphql: ^4.0.0
This package is auto-updated.
Last update: 2024-12-08 14:53:08 UTC
README
Create, manage and validate structured yaml/json formatted text data and make it available through graphQL
Installation
Install through composer: composer require oposs/silverstripe-structured-data
.
To enable the graphQL type, add the following lines to your app/_config/graphql.yml
:
SilverStripe\GraphQL\Schema\Schema: schemas: default: src: - 'oposs/silverstripe-structured-data: _graphql'
If you just need a form field which can be validated against a JSON schema, you may want to disable the admin backend:
Oposs\StructuredData\Extensions\StructuredDataAdmin: show_admin_interface: false
Permissions
Global permissions provided by this module:
STRUCTURED_DATA_VIEW
: Ability to view the Structured Data Module and stored data and schemasSTRUCTURED_DATA_ADMIN
: Users holding this permission can edit/create/delete all data and schemas
Fine-grained control over editing access is possible by defining allowed groups for each data object individually.
Usage
Besides the possibility to access the data via graphQL this module also provides a specialized StructuredDataField
which can be
setup to validate it's input against a schema:
<?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 example
{ "query": "{ readStructuredDatas(filter: {key: {eq: \"test-data\"}}) { nodes { asJsonBlob structured_data } }}" }