diff --git a/source/development/frontend/models.rst b/source/development/frontend/models.rst index a669fef..7ca4829 100644 --- a/source/development/frontend/models.rst +++ b/source/development/frontend/models.rst @@ -20,4 +20,5 @@ In this chapter we will explain how models are designed and build. models_example models_guidelines models_fieldtypes + models_customfields models_constraints diff --git a/source/development/frontend/models_customfields.rst b/source/development/frontend/models_customfields.rst new file mode 100644 index 0000000..06dea25 --- /dev/null +++ b/source/development/frontend/models_customfields.rst @@ -0,0 +1,72 @@ +----------------------------------- +Custom (app specific) field types +----------------------------------- + +Applications can add their own custom field types, which should be derived from :code:`BaseField` or one of its descendants. +A very simple single item custom field type could look like this: + +Build the field type +........................................ + +.. code-block:: php + + 'can not use a reserved word', + 'domain' => $reservedwords)); + } + return $validators; + } + +This example extends the standard validations with a list of reserved words, in which case it would yield :code:`can not use a reserved word` +if one of the reserved words are provided. + +.. Note:: + + This file should be placed in the subdirectory :code:`FieldTypes` of the model itself. + +.. Tip:: + + Use :code:`BaseListField` as simple template for list type items. + + +Use in model +................. + +The validation can be used as any standard type, but using :code:`.\` the model knows it concerns a local field. + +.. code-block:: xml + + + //OPNsense/MyFirst/App + 1.0.0 + + My first application + + + + + Y + + + + + + +.. Tip:: + + Inspect the `basic field `__ types + for inspiration, a concrete example of a custom field type can be found in the + `firewall `__ section