Let the platform do the work

Dependencies

Overview

Dependencies create dependent actions for fields and forms that can leverage more complicated logic.

Properties

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

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

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/Dependencies/<file>.php to map a new dependency in the system. The following example will create a new required field dependency on a module that is evaluated upon editing a record:

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

  <?php

$dependencies['<module>']['<unique name>'] = array(
    'hooks' => array("edit"),
    //Trigger formula for the dependency. Defaults to 'true'.
    'trigger' => 'true',
    'triggerFields' => array('<trigger field>'),
    'onload' => true,
    //Actions is a list of actions to fire when the trigger is true
    'actions' => array(
        array(
            'name' => 'SetRequired', //Action type
            //The parameters passed in depend on the action type
            'params' => array(
                'target' => '<field>',
                'label'  => '<field label>', //normally <field>_label
                'value' => 'equal($<trigger field>, "Closed")', //Formula
            ),
        ),
    ),
);

Next, navigate to Admin > Repair > Quick Repair and Rebuild. The system will then rebuild the extensions, compiling your customization into./custom/modules/<module>/Ext/Dependencies/deps.ext.php, and the dependency will be in place.

Module Loadable Package

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

Installdef Properties

Name Type Description
from String The base path of the file
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 Dependency file to a specific module. You should note that when using this approach, Sugar will automatically execute Rebuild Extensions to reflect the new Dependency in the system.

./manifest.php

  <?php

$manifest = array(
    ...
);

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

Alternatively, you may use the $installdefs['copy'] index for the Dependency Extension file. When using this approach, you may need to manually run a repair action 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.

Topics