Let the platform do the work

Fields

Overview

How fields interact with the various aspects of Sugar. 

SugarField Widgets

The SugarField widgets, located in ./include/SugarFields/Fields/ , define the data formatting and search query structure for the various field types. They also define the rendering of fields for modules running in backward compatibility mode. When creating or overriding field widgets, developers should place their customization in ./custom/include/SugarFields/Fields/. For information on how Sidecar renders fields, please refer to the fields section in our user interface documentation. Creating Custom Fields

Implementation

All fields for a module are defined within vardefs. Within this definition, the type attribute will determine all of the logic applied to the field. For example, the Contacts module has a  'Do Not Call' field. In the vardefs, this field is defined as follows:

'do_not_call' => array (
    'name' => 'do_not_call', // the name of the field
    'vname' => 'LBL_DO_NOT_CALL', // the label for the field name
    'type' => 'bool', // the fields type
    'default' => '0', // the fields default value
    'audited'=>true, // whether the field is audited
    'duplicate_on_record_copy' => 'always', // whether to duplicate the fields value when being copied
    'comment' => 'An indicator of whether contact can be called' // admin context of the field
),

 The bool type field is rendered in the UI from the ./clients/base/fields/bool/bool.js field controller which renders the appropriate handlebars template as defined by the users current view for sidecar enabled modules. When the user saves data, the controller formats the data for the API and passes it to an endpoint. Once the data is received by the server, The SugarField definition calls any additional logic in the apiSave function to format the data for saving to the database. The same concept is applied in the apiFormatField function when retrieving data from the database to be passed back to the user interface through the API. For modules running in backward compatibility mode, the bool field is rendered using the Smarty .tpl) templates located in ./include/SugarFields/Fields/Bool/.

While the vardefs define the default type for a field, this value can be overridden in the metadata of the view rendering the field. The example being that in ./custom/modules/Contacts/clients/base/views/record/record.php, you can modify the do_not_call field array to point to a custom field type you have created. For more information on creating custom field types, please refer to Creating Custom Fields documentation.