|
| 1 | +.. _rst_cookbook_panels_default-values: |
| 2 | + |
| 3 | +Input screens: pre-defined values |
| 4 | +================================= |
| 5 | + |
| 6 | +You can fill the input fields automatically with pre-defined default values. This makes it easier for users to fill in the fields, when they have to add a new data record. |
| 7 | + |
| 8 | +You can treat the MetaModels input fields in (almost) the same way as the input fields of the Contao core or standard extensions, which have been created with a DCA array. Differences may be partly caused by the dynamic generation of the fields in MetaModels by the DC-general. |
| 9 | + |
| 10 | +You can create your pre-defined values by adding them to the DC array with the key "default". You can amend the array either by an addition in the file "dcaconfig.php" in "/system/config/" or, if there is a custom module folder, in "config.php". |
| 11 | + |
| 12 | +The respective entries are already preconfigured in "config.php" in the module `"Metamodels-Boilerplate" <https://github.com/MetaModels/boilerplate>`_ . |
| 13 | + |
| 14 | +In order to create a pre-defined value you need to know the (internal) name of the MetaModel and also the name of the column. Then you can add this details in an array in the following format: |
| 15 | + |
| 16 | +.. code-block:: php |
| 17 | + :linenos: |
| 18 | + |
| 19 | + <?php |
| 20 | + $GLOBALS['TL_DCA']['<MM-Table-Name>']['fields']['<Field-Column-Name>']['default'] = <Value>; |
| 21 | +
|
| 22 | +For an email field ([text]) from :ref:`mm_first_index` a pre-defined value could look as follows: |
| 23 | + |
| 24 | +.. code-block:: php |
| 25 | + :linenos: |
| 26 | + |
| 27 | + <?php |
| 28 | + $GLOBALS['TL_DCA']['mm_employeelist']['fields']['email']['default'] = '@mmtest.com'; |
| 29 | +
|
| 30 | +There are specific requirements how the values are expected for each type of attribute : |
| 31 | + |
| 32 | +* **Text**: Text in quotation marks e.g. '@mmtest.com' |br| |
| 33 | + ``...['default'] = '@mmtest.com';`` |
| 34 | +* **Timestamp**: Integer for the timestamp e.g. 1463657005 or PHP function time() |br| |
| 35 | + ``...['default'] = 1463657005;`` or |br| |
| 36 | + ``...['default'] = time();`` |
| 37 | +* **Select**: Integer of the ID of the value in quotation marks |br| |
| 38 | + ``...['default'] = '2';`` |
| 39 | +* **Multiple selection**: Array with alias values from pre-defined alias column |br| |
| 40 | + ``...['default'] = array('sales', 'marketing');`` |
| 41 | +* **Checkbox (Checkbox)**: true |br| |
| 42 | + ``...['default'] = true;`` |
| 43 | + |
| 44 | + |
| 45 | +As you can see with the attribute "Timestamp", dynamic defaults are feasible. It would be possible to fall back on existng MetaModels values and to output them as default - with computation if necessary. The API methods (:ref:`ref_api_interf_mm`) are available to get access to MetaModels. |
| 46 | + |
| 47 | + |
| 48 | +.. |br| raw:: html |
| 49 | + |
| 50 | + <br /> |
0 commit comments