Adding Custom Tab Logic

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

1. Example of Custom Tab Logic

In this example we are going to see how to add custom tab logic in order to hide a tab based on a field’s value.

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. How does this look as Code?

<?php
...
    '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'
                            ],
                        ],
                    ],
                ],
            ],
        ],

...

When adding this configuration, it can either be added to the vardefs.php or the detailviewdefs.php.

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

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.

<?php

...
'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:

<?php
...
'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':

<?php
...
    '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.