Skip to content

Datamanager Schemas

flack edited this page Sep 26, 2019 · 10 revisions

Datamanager Schemas are used to configure Datamanager-powered forms. In spite of the similar-sounding name, they are not related to the MgdSchema XML files, which are used to describe the database table layout.

Almost all forms in Components are based on Datamanager Schemas, and their data structure as well as validation and other rules can be altered by user-defined Schemas. The default schema is usually located in config/schemadb_default.inc.

Structure

Here's an example of what a simple Datamanager Schema might look like:

'default' => [
    'description' => 'article',
    'fields'      => [
        'name' => [
            'title'   => 'url name',
            'storage' => 'name',
            'type'    => 'urlname',
            'widget'  => 'text',
            'type_config' => [
                'allow_catenate' => true,
            ],
        ),
        'title' => [
            'title' => 'title',
            'storage' => 'title',
            'required' => true,
            'type' => 'text',
            'widget' => 'text',
        ],
        'abstract' => [
            'title' => 'abstract',
            'storage' => 'abstract',
            'type' => 'text',
            'widget' => 'textarea',
        ],
        'content' => [
            'title' => 'content',
            'storage' => 'content',
            'required' => true,
            'type' => 'text',
            'type_config' => [
                'output_mode' => 'html'
            ],
            'widget' => 'tinymce',
        ],
        'related' => [
            'title' => 'related stories',
            'storage' => 'extra3',
            'type' => 'select',
            'type_config' => [
                 'require_corresponding_option' => false,
                 'allow_multiple' => true,
                 'options' => [],
                 'multiple_storagemode' => 'imploded_wrapped',
            ],
            'widget' => 'autocomplete',
            'widget_config' => [
                'clever_class' => 'article',
            ],
        ],
        'image' => [
            'title' => 'image',
            'storage' => null,
            'type' => 'image',
            'type_config' => [
                'filter_chain' => 'resize(800, 600)',
                'auto_thumbnail' => array(200, 200),
            ],
            'widget' => 'image',
            'hidden' => true,
        ],
    ],
],

Aside from specifying the data type, field name and storage location, Schemas are the place where widgets are assigned to content, and input validation can be triggered.

Schema fields have the following main properties:

Storage

This is used to tell the system where to store the contents of the field. These can be the fields the object has in the database. In addition to regular Midgard fields, two other possibilities exist:

  • parameter - store the content to a Parameter of the object
  • attachment - store the content to a file Attachment of the object

Furthermore, it is possible to specify null as the storage location, which means that no automatic storage will happen or tmp, which will save contents in a temporary object.

Type

The type setting determines how a field's data is treated in PHP

Widgets

The widget setting determines how the field will be rendered in the form

Standard HTML Widgets

  • checkbox - creates HTML input type="checkbox"
  • hidden - creates HTML input type="hidden"
  • password - creates HTML input type="password"
  • radiocheckselect - creates HTML input type="radio" or type="checkboxs"
  • select - creates HTML select
  • text - creates HTML input type="text"
  • textarea - creates HTML textarea

Specialized Widgets

Javascript Widgets

AJAX widgets

Creating custom Schemas

To create your own Datamanager Schema, just override the include path in the Component configuration:

 "schemadb"       => "path-to-my-schema",

path-to-my-schema should then include the schema you want to use