Let the platform do the work

Vardefs

Overview

The Vardefs extension adds or overrides system vardefs, which provide the Sugar application with information about SugarBeans.

For more information on vardefs in Sugar, please refer to the Vardefs documentation .

Properties

The following extension properties are available. For more information, please refer to the Extension Property documentation.

Property Value
Extension Scope Module
Sugar Variable $dictionary
Extension Directory ./custom/Extension/modules/<module>/Ext/Vardefs/
Compiled Extension File ./custom/<module>/Ext/Vardefs/vardefs.ext.php
Manifest Installdef $installdefs['vardefs']

Implementation

The following sections illustrate the various ways to implement a customization to a Sugar instance.

File System

When working directly with the filesystem, you can create a file in ./custom/Extension/modules/<module>/Ext/Vardefs/ to edit or add vardefs to a module in the system.

The most common use of the Vardef extension is to alter the attributes of an existing vardef. To do this,avoid redefining the entire vardef and instead update the specific index you want to change. The following example updates the Required property on the Name field in a module:

./custom/Extension/modules/<module>/Ext/Vardefs/<file>.php

$dictionary['<module>']['fields']['name']['required'] = false;

Next, navigate to Admin > Repair > Quick Repair and Rebuild. The system will then rebuild the extensions and your customizations will be compiled into ./custom/modules/<module>/Ext/Vardefs/vardefs.ext.php .

Notice  Never specify vardefs for a module under another module's extension path. For example, do not specify $dictionary['Accounts']['fields']['name']['required'] = false under ./custom/Extension/modules/Contacts/Ext/Vardefs/. Doing so will result in unexpected behavior within the system.

Module Loadable Package

When building a module loadable package, you can use the $installdefs['vardefs'] index to install the extension file.

Installdef Properties

Name Type Description
from String The base path of the file to be installed
to_module String The key for the module where the file will be installed

The example below demonstrates the proper install definition that should be used in the ./manifest.php file in order to add the Vardefs file to a specific module. You should note that when using this approach Sugar will automatically execute Rebuild Extensions to reflect the vardef changes in the system.

./manifest.php

<?php

$manifest = array(
    ...
);

$installdefs = array(
    'id' => 'vardefs_Example',
    'vardefs' => array(
        array(
            'from' => '<basepath>/Files/custom/Extension/modules/<module>/Ext/Vardefs/<file>.php',
            'to_module' => '<module>',
        )
    )
);

Alternatively, you may use the $installdefs['copy'] index to copy the file. When using this approach, you may need to manually run repair actions such as a Quick Repair and Rebuild. For more information on the $installdefs['copy'] index and module-loadable packages, please refer to the Introduction to the Manifest page.

Creating Custom Fields

If your goal is to manually create a custom field on an instance, you should be using the Module Installer to create the field. This can be used both for an installer package and programmatically. An example of creating a field from a module loadable package can be found under Package Examples in the article, Creating an Installable Package that Creates New Fields. An example of programmatically creating a field can be found in the Manually Creating Custom Fields section of the Module Vardefs documentation.