PHP code example of oposs / silverstripe-structured-data
1. Go to this page and download the library: Download oposs/silverstripe-structured-data library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
oposs / silverstripe-structured-data example snippets
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');