Let the platform do the work

SetPanelVisibility

Overview

The SugarLogic SetPanelVisibility action, defined in ./include/Expressions/Actions/PanelVisibilityAction.php, is used to determine the visibility of a record view panel based on a formula. 

Implementation

While the dependency metadata for your module can be defined in ./modules/<module>/metadata/dependencydefs.php and  ./custom/modules/<module>/metadata/dependencydef.php, it is recommended to use the extension framework when customizing stock modules to prevent third-party plugins from conflicting with your customizations. The following section will demonstrate how to implement a read-only dependency.

SetPanelVisibility Parameters

Parameter Type Description
target String The id of the panel to hide
value String Formula used to determine if the panel should be visible.

For more information on the various parameters in the dependency definitions, please refer to the dependency actions documentation.

Example

For our example, we will create a dependency on the Cases module that will hide a specific panel if the status field on a case is set to "Closed". Our example extension definition is shown below: 

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

  <?php

$dependencies['Cases']['panel_2_visibility'] = array(
    'hooks' => array("edit","view"),
    'trigger' => 'equal($status, "Closed")',
    'triggerFields' => array('status'),
    'onload' => true,
    //Actions is a list of actions to fire when the trigger is true
    'actions' => array(
        array(
            'name' => 'SetPanelVisibility',
            'params' => array(
                'target' => 'detailpanel_2',
                'value' => 'true',
            ),
        )
    ),
    //notActions is a list of actions to fire when the trigger is false
    'notActions' => array(
        array(
            'name' => 'SetPanelVisibility',
            'params' => array(
                'target' => 'detailpanel_2',
                'value' => 'false',
            ),
        ),
    ),
);

Once you have the file in place, you will need to navigate to Admin > Repairs > and run a Quick Repair and Rebuild.

Note: It is important that the module name is plural ('Cases' vs. 'Case') and that the name of the dependency, "panel_2_visibility" in this example, is unique.