Adding Panel/Tab Display Logic

When making these changes be sure to make them in the custom directory, ie: 'public/legacy/custom/modules/<module>/…​'

1. Introduction

Display logic allows you to define rules to hide and show panels/tabs depending on field values.

1.1 Example scenario

As an example we will hide the More Information tab on Accounts if the Name is Example.

Shown Tab - Name Example

Hidden Tab - Name Example

2.Logic Metadata definition

The first thing to define is the displayLogic entry in the metadata. This is where we are going to define the triggers for hide/display our panel.

The configuration for the logic can be added only to detailviewdefs.php.

When adding this code be sure to add it below newTab within the tabDefs.

In the following example we are going to add them to the Accounts module detailviewdefs.php.

2.1 Steps to add the logic on the custom detailviewdefs.php

  1. Copy the core Accounts detailviewdefs.php to the custom folder:

    1. From: public/legacy/modules/Accounts/metadata/detailviewdefs.php

    2. To: public/legacy/custom/modules/Accounts/metadata/detailviewdefs.php

  2. Replace the LBL_PANEL_ADVANCED entry on the custom detailviewdefs.php with the code on the snippet below

    • Re-set permissions if needed (will depend on your setup)

  3. Run Repair and Rebuild on Admin menu

    'LBL_PANEL_ADVANCED' =>
        [
            'newTab' => true,
            'panelDefault' => 'expanded',
            'displayLogic' => [
                'hide_on_name' => [
                    'key' => 'displayType',
                    'modes' => [
                        0 => 'detail',
                        1 => 'edit',
                        2 => 'create',
                    ],
                    'targetDisplayType' => 'hide',
                    'params' => [
                        'fieldDependencies' => [
                            'name'
                        ],
                        'activeOnFields' => [
                            'name' => [
                                'Example'
                            ],
                        ],
                    ],
                ],
            ],
        ],

3. Properties Description

  • Key

    • The key within the named displayLogic array is stating which logic type will be used for the following. In this case it’s displayType.

  • Modes

    • Modes are views you would like your required logic to take effect on, as shown above it will be detail, edit and create. Another example of a mode that could be selected could be list for example.

Field Dependencies

fieldDependencies is where you declare the field(s) that you would like your logic to depend on.

'fieldDependencies' => [
    'name',
]

Active on Fields

activeOnFields is where you declare the field/values that trigger the change of the tab to be shown/hidden.

In the example above we have the tab More Information to hide when name is Example.

If we wanted it to hide if it was either Example or another value such as User then a new value would be added like so:

'activeOnFields' => [
  'name' => ['Example', 'User'],
],

Hidden Tab - Name User

Target Display Type

targetDisplayType should be either show or hide.

If you have a tab you would like to hide until a field has a certain value, you can add 'display' ⇒ 'hide':

    'LBL_PANEL_ADVANCED' =>
        [
            'newTab' => true,
            'display' => 'hide',
            'panelDefault' => 'expanded',
            'displayLogic' => [
                'hide_on_name' => [
                    'key' => 'displayType',
                    'modes' => [
                        0 => 'detail',
                        1 => 'edit',
                        2 => 'create',
                    ],
                    'targetDisplayType' => 'show',
                    'params' => [
                        'fieldDependencies' => [
                            'name'
                        ],
                        'activeOnFields' => [
                            'name' => [
                                'Example',
                            ],
                        ],
                    ],
                ],
            ],
        ],

Content is available under GNU Free Documentation License 1.3 or later unless otherwise noted.