Datamanager 2 Widget base class.

As with all subclasses, the actual initialization is done in the initialize() function, not in the constructor, to allow for error handling.

Quick glance at the changes

  • No more form prefixes, use the field name as a form field name
  • Now uses class members, which should use initializers (var $name = 'default_value';) for configuration defaults.
  • The schema configuration ('widget_config') is merged using the semantics $widget->$key = $value;
package midcom.helper.datamanager2

 Methods

__construct ($renderer)

Constructor.

Nothing fancy, the actual startup work is done by the initialize call.

Parameters

$renderer

_on_configuring ()

This function is called before the configuration keys are merged into the types configuration.

_on_initialize ()

This event handler is called during construction, so passing references to $this to the outside is unsafe at this point.

Returns

booleanIndicating success, false will abort the type construction sequence.

_translate (string $string)

This is a shortcut to the translate_schema_string function.
see \midcom_helper_datamanager2_schema::translate_schema_string()

Parameters

$string

stringThe string to be translated.

Returns

stringThe translated string.

add_elements_to_form ($attributes)

This call adds the necessary form elements to the form passed by reference.

Parameters

$attributes

freeze ()

Freezes all form elements associated with the widget.

The default implementation works on the default field name, you don't need to override this function unless you have multiple widgets in the form.

This maps to the HTML_QuickForm_element::freeze() function.

get_default ()

Returns the default value for this field as required by HTML_Quickform.

You may either return a single value for simple types, or an array of form field name / value pairs in case of composite types. A value of null indicates no applicable default from the type or storage, in which case defaults from the handler or the DM2 schema can be applied.

This default implementation returns null unconditionally.

Returns

mixedThe default value as outlined above.

get_external_config (string $key)

Gets an external configuration option referenced by its key.

Besides other parts in the datamanager framework, nobody should ever have to touch this information.

Parameters

$key

stringThe key by which this configuration option is referenced.

Returns

mixedThe configuration value, which is null if the key wasn't found.

initialize (string $name, array $config, \midcom_helper_datamanager2_schema $schema, \midcom_helper_datamanager2_type $type, string $namespace, boolean $initialize_dependencies)

Initializes and configures the widget.

Parameters

$name

stringThe name of the field to which this widget is bound.

$config

arrayThe configuration data which should be used to customize the widget.

$schema

\midcom_helper_datamanager2_schemaThe full schema object.

$type

\midcom_helper_datamanager2_typeThe type to which we are bound.

$namespace

stringThe namespace to use including the trailing underscore.

$initialize_dependencies

booleanWhether to load JS and other dependencies on initialize

Returns

booleanIndicating success. If this is false, the type will be unusable.

is_frozen ()

Checks if the widget is frozen.

The default implementation works on the default field name, usually you don't need to override this function unless you have some strange form element logic.

This maps to the HTML_QuickForm_element::isFrozen() function.

Returns

booleanTrue if the element is frozen, false otherwise.

on_submit (array $results)

This event handler is called if and only if the Formmanager detects an actual form submission (this is tracked using a hidden form member).

No Form validation has been done at this point. The event is triggered on all submissions with the exception of the cancel and previous form events.

You should be careful when using this event for data processing therefore. Its main application is the processing of additional buttons placed into the form by the widget.

The implementation of this handler is optional.

Parameters

$results

arrayThe complete form results, you need to extract all values relevant for your type yourself.

render_content ()

When called, this method should display the current data without any editing widget or surrounding braces in plain and simple HTML.

The default implementation calls the type's convert_to_html method.

Returns

stringThe rendered HTML

set_external_config (string $key, mixed $value)

Sets an external configuration option.

Besides other parts in the datamanager framework, nobody should ever have to touch this information.

Parameters

$key

stringThe key by which this configuration option is referenced.

$value

mixedThe configuration value.

set_form (\HTMLQuickForm $form)

Set the form reference.

Parameters

$form

\HTMLQuickForm&$form The form to use.

set_state (string $state)

Set the formmanager state

Parameters

$state

stringThe state we're in.

sync_type_with_widget (array $results)

This function is invoked if the widget should extract the corresponding data from the form results passed in $results.

Form validation has already been done before, this function will only be called if and only if the form validation succeeds.

Parameters

$results

arrayThe complete form results, you need to extract all values relevant for your type yourself.

unfreeze ()

Unfreezes all form elements associated with the widget.

The default implementation works on the default field name, you don't need to override this function unless you have multiple widgets in the form.

This maps to the HTML_QuickForm_element::unfreeze() function.

 Properties

 

Array $_field

A reference to the schema field we should draw.

Description texts etc. are taken from here.

access protected
 

\HTML_QuickForm $_form

The QuickForm we are using.
access protected
 

\HTML_QuickForm_Renderer $_renderer

The QuickForm renderer we are using.
access protected
 

\midcom_helper_datamanager2_schema $_schema

The schema (not the schema <i>database!</i>) to use for operation.

This variable will always contain a parsed representation of the schema, so that one can swiftly switch between individual schemas of the Database.

access protected
 

\midcom_helper_datamanager2_type $_type

This is a reference to the type we're based on.
access protected
 

string $name

The name field holds the name of the field the widget is encapsulating.

This maps to the schema's field name. You should never have to change them.

 

boolean $_initialize_dependencies

Whether widget should always load its dependencies on initialization, or only during add_elements_to_form call.
 

string $_namespace

This is the Namespace to use for all HTML/CSS/JS elements.

It is deduced by the formmanager and tries to be as smart as possible to work safely with more then one form on a page.

You have to prefix all elements which must be unique using this string (it includes a trailing underscore).

 

Array $_external_config

This variable contains configuration data which is not directly related to the operation of the type, but required for the operation of external tools like the storage manager.

The type should never touch this variable, which is controlled by a corresponding getter/setter pair.

see \set_external_config()
see \get_external_config()
 

string $_state

State of the form manager