Datamanager 2 Schema class.

This class encapsulates Datamanager Schemas. It contains all information required to construct the types and widgets of a given data schema. The base class constructs out of a Datamanager 2 Schema definition, you need to use the appropriate subclass to handle them dynamically.

Schema Definition

Storage When using the Midgard storage backend, it is possible to define a callback class to be called that will then save the object. The class is defined as follows. Please note that if the classname follows the midcom hierarchy, it may be loaded automatically.

The class must satisfy the following interfaces:

class midcom_admin_parameters_callback {
     // params:
     // name: the name of the field
     // data: the data that comes from the type defined.
     // storage: a reference to the datamanager's storageclass.
     function on_load_data($name,&$storage);
     function on_store_data($name, $data,&$storage);

What the functions should return depends on the datatype they return to.

The callback may be defined in the schema like this:

'fields' => Array
     'parameters' => Array
          'title' => 'url name',
          'storage' => Array
                  'location' => 'object',
                  'callback' => 'midcom_admin_parameters_callbacks_storage',
           'type' => ..,
           'widget' => ..

Important It is only possible to define one storage callback per schema! If you want more than one, encapsulate this in your class.

todo Complete documentation
package midcom.helper.datamanager2


__construct (mixed $schemadb, string $name, $schemadb_path)

Construct a schema, takes a schema snippet URI resolvable through the midcom_helper_misc::get_snippet_content() helper function.



mixedEither the path or the already loaded schema database to use.


stringThe name of the Schema to use. It must be a member in the specified schema database. If unspecified, the default schema is used.


append_field (string $name, array $config)

This function adds a new field to the schema, appending it at the end of the current field listing.

This is callable after the construction of the object, to allow you to add additional fields like component required fields to the list.

This can also be used to merge schemas together.

It will complete the field's default and set the corresponding type and widget setups.



stringThe name of the field to add


arrayThe fields' full configuration set.

load_database (mixed $raw_db)

Helper function which transforms a raw schema database (either already parsed or based on a URL to a schemadb) into a list of schema class instances.
see \midcom_helper_misc::get_snippet_content()



mixedEither an already created raw schema array, or a midcom_helper_misc::get_snippet_content compatible URL to a snippet / file from which the db should be loaded or schemadb contents as a string.


ArrayAn array of midcom_helper_datamanager2_schema class instances.

register_to_session ($guid)

Registers a schema into the session so it is readable by the imagepopup.




stringthe form sessionkey

translate_schema_string (string $string)

Schema translation helper, usable by components from the outside.

The l10n db from the schema is used first, the Datamanager l10n db second and the MidCOM core l10n db last. If the string is not found in both databases, the string is returned unchanged.

Note, that the string is translated to lower case before translation, as this is the usual form how strings are in the l10n database. (This is for backwards compatibility mainly.)



stringThe string to be translated.


stringThe translated string.

_complete_field_defaults ($config)

Internal helper function which completes all missing field declaration members so that all fields can be treated uniformly.
todo Refactor in subfunctions for better readability.



_complete_validation_field ($config)



_load_schema (string $name)

This function parses the schema and populates all members with the corresponding information, completing defaults where necessary.

It will automatically translate all descriptive fields according to the rules outlined in the translate_schema_field() helper function.



stringThe name of the schema to load.

_load_schemadb (mixed $schemadb)

This function loads the schema database into the class, either from a copy already in memory, or from a URL resolvable by midcom_helper_misc::get_snippet_content.



mixedEither the path or the already loaded schema database to use.

_load_schemadb_contents (mixed $schemadb)

Load the schemadb contents
see \midcom_helper_misc::get_snippet_content()



mixedPath of the schemadb or raw schema array


arrayContaining schemadb definitions



Array $customdata

This array holds custom information attached to this schema.

Its exact usage is component dependant.


string $description

The title of this schema, used to display schemas when

Array $field_order

A simple array holding the fields in the order they should be rendered identified by their name.

Array $fields

The general field listing, indexed by their name.

It contains the full field record which has been completed with all defaults.

You may changes settings outlined here, be aware though, that types and/or widgets spawned based on this schema do normally not reference these configuration block directly, but instead they usually merge the settings made into their own internal default config. You can still adjust the types, which usually have their settings available as public members though.


Array $filters

Custom data filter rules.

This is a list of arrays. Each array defines a single callback, a field list according to HTML_QuickForm::applyFilter() along with a snippet or file location that should be auto-loaded in case the function is missing.


\midcom_services_i18n_l10n $l10n_schema

The primary L10n DB to use for schema translation.

string $name

The name of the schema ("identifier").

Array $operations

The operations to add to the form.

This is a simple array of commands, valid entries are 'save', 'cancel', 'next' and 'previous', 'edit' is forbidden, other values are not interpreted by the DM infrastructure.


Array $validation

Form-wide validation callbacks, executed by QuickForm.

This is a list of arrays. Each array defines a single callback, along with a snippet or file location that should be auto-loaded in case the function is missing.


Array $_raw_schema

The raw schema array as read by the system.

This is a reference into the schema database.


Array $_raw_schemadb

The raw schema database as read by the system.

Array $_schemadb_path

The schema database path as read by the system.