# Custom Uitypes

You can add new types to the existing ones and manage them completely without changing other code. The procedure for creating a new one is:

1. Create a new custom field with the new type (nnn)
2. Create the files:  
    a. nnn.php in modules/SDK/examples  
    b. nnn.js in modules/SDK/examples  
    c. nnn.tpl in Smarty/templates/modules/SDK/examples  
    These files manage the behavior of the new field depending on the context (list, detail, and so on)
3. Register the new type with the class method SDK::setUitype.

In modules/SDK/examples/VTE-SDK-2.php there are various examples of field creation and uitype registration.  
In modules/SDK/doc/VTE-SDK-2.pdf under **Uitypes List** you can find the list of the main standard uitypes.

```PHP
SDK::setUitype($uitype, $src_php, $src_tpl, $src_js, $type='', $params='');
```

*$uitype : the number of the new type; it must be nnn (the name of the files)*  
*$src\_php: the path of nnn.php*  
*$src\_tpl: the path of nnn.tpl (without Smarty/templates/ at the beginning)*  
*$src\_js : the path of nnn.js*  
*$type : the type in webservice format (‘text’, ‘boolean’, and so on)*  
*$params : not used yet*

To remove the uitype:

```
SDK::unsetUitype($uitype);
```

*$uitype : it is the number of the uitype to remove (the files associated with it will not be deleted)*

<p class="callout warning">We recommend using uitype with a value greater than 2000, to avoid conflicts with the future releases of **vtenext**.</p>

The php script has several variables available, the first one is:

*$sdk\_mode : the views that can be customized for the new uitype (“insert”, “detail”, “edit”, “relatedlist”, “list”, “pdfmaker”, “report”, and so on)*

Depending on the type of $sdk\_mode, various variables can be read and modified.

**detail**  
to manage the display of the field in DetailView  
*INPUT*  
*$module : the current module name*  
*$fieldlabel: the label of the field*  
*$fieldname : the name of the field*  
*$col\_fields: (array) the values of the fields*  
*OUTPUT*  
*$label\_fld\[\] : the label translated*  
*$label\_fld\[\] : the value to be displayed*

**edit**  
to manage the display of the field in EditView  
*INPUT*  
*$module\_name : the current module name*  
*$fieldlabel : the label of the field*  
*$value : the value of the field*  
*OUTPUT*  
*$editview\_label\[\] : the label translated*  
*$fieldvalue\[\] : the value to be displayed*

**relatedlist, list, pdfmaker**  
to manage the display of the field in ListView, RelatedList and PDFMaker  
*INPUT*  
*$sdk\_value : the value of the field*  
*OUTPUT*  
*$value : the value to be displayed*

**report**  
to manage the display of the field in Report  
*INPUT*  
*$sdk\_value : the value of the field*  
*OUTPUT*  
*$fieldvalue : the value to be displayed*

<p class="callout warning">If the value to be displayed from the interface **is formatted differently** than the value saved in the database (e.g. number 1.000,25 which must be saved as 1000.25) then the following methods must also be managed to save the value in the correct format and search for it.</p>

**insert**  
to convert the value to the format to be saved in the database  
*INPUT*  
*$this-&gt;column\_fields : (array) the values of the fields*  
*$fieldname : the name of the field*  
*OUTPUT*  
*$fldvalue : the value to save in the database*

**formatvalue**  
to convert the value coming from the $\_REQUEST into the format saved in the database (used in the new management of Conditional Fields)  
*INPUT*  
*$value : the value of the field*  
*OUTPUT*  
*$value : the value converted to database format*

**querygeneratorsearch**  
to convert the value searched in the lists and filters by the user  
*INPUT AND OUTPUT*  
*$fieldname : the name of the field*  
*$operator : the comparison operator*  
*$value : the value searched*

**customviewsearch**  
to manage the conversion of the value in the popup filters for the reference fields  
*INPUT AND OUTPUT*  
*$tablename : the table of the field*  
*$fieldname : the name of the field*  
*$comparator : the comparison operator*  
*$value : the value searched*

**popupbasicsearch**  
to manage the conversion of the value in the popup search for the reference fields  
*INPUT*  
*$table\_name : the table name*  
*$column\_name : the column name*  
*$search\_string : the value searched*  
*OUTPUT*  
*$where : the condition of the query*  
*e.g. $where = "$table\_name.$column\_name = '".convertToDBFunction($search\_string)."'";*

**popupadvancedsearch**  
to manage the conversion of the value in the advanced popup search for the reference fields  
*INPUT AND OUTPUT*  
*$tab\_col : the table and the column of the field*  
*$srch\_cond : the comparison operator*  
*$srch\_val : the value searched*

**reportsearch**  
to convert the value searched in the reports by the user  
*INPUT AND OUTPUT*  
*$table : the table of the field*  
*$column : the column of the field*  
*$fieldname : the field name*  
*$comparator : the comparison operator*  
*$value : the value searched*

<p class="callout info">**Hooks**  
data/CRMEntity.php  
include/ListView/ListViewController.php  
include/utils/crmv\_utils.php  
include/utils/EditViewUtils.php  
include/utils/DetailViewUtils.php  
include/utils/ListViewUtils.php  
include/utils/SearchUtils.php  
include/QueryGenerator/QueryGenerator.php  
modules/PDFMaker/InventoryPDF.php  
modules/Reports/ReportRun.php  
modules/Users/Users.php  
modules/CustomView/Save.php  
modules/CustomView/CustomView.php  
Smarty/templates/DisplayFieldsReadonly.tpl  
Smarty/templates/DisplayFieldsHidden.tpl  
Smarty/templates/DetailViewFields.tpl  
Smarty/templates/EditViewUI.tpl  
Smarty/templates/DetailViewUI.tpl</p>