AnsweredAssumed Answered

Unsetting subpanels works for core subpanels but not custom ones

Question asked by Ramblin Ramblin on Mar 5, 2014
Latest reply on Sep 2, 2014 by Przemysław Lib
SugarCRM CE 6.5.16 on stock CentOS 6.4

I know how to unset a subpanel based on the value in a variable and it has worked quite well for me - so long as the subpanel I am unset(ting) is one defined in the core SugarCRM files (which in this case has them located at (sugar_root)/modules/Accounts/metadata/subpaneldefs.php).

However, I just tried to unset a subpanel for a relationship between Accounts and a custom module (created in Module Builder) and the custom subpanel would not unset.  The custom subpanel does properly show in the Accounts detailview but it will not unset; the unset command is basically ignored. 

I put some test code in place to make sure the script was being executed (tested hiding 'bugs' and 'cases' modules) and the script works.  But the unset of the subpanel to the custom module does not work.

Any ideas?


I want to hide the custom subpanel so it does NOT show in the Accounts detailview (will worry about editview when I get this working) when the Account Type is NOT one of:
- FacilitatorCo
- Venue
- Caterer

To do this:

Add entries to the account_type_dom list:
- FacilitatorCo
- Venue
- Caterer

Add a custom module (using Module Builder) named EvMgr_Evs

From the EvMgr_Evs module, create (using Module Builder) a Many<->Many relationship between EvMgr_Evs and Accounts

Add the following custom code into (sugar_root)/custom/Extension/modules/Accounts/Ext/Layoutdefs/accounts_subpanel_display_code.php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

// If the Account Type is NOT FacilitatorCo or Venue or Caterer, we will not be displaying the Events subpanel
// If the Account Type is NOT Venue or Caterer, we will not be displaying the ForVenues or ForCaterers subpanels
// Get the subpanel names for built-in subpanels from <sugar_root>/modules/Accounts/metadata/subpaneldefs.php
// Get the subpanel names for added subpanels (after Installing the Published package) from <sugar_root>/custom/Extension/modules/Accounts/Ext/Layoutdefs/<subpanel_def_file>
// or  (before installing Published Package) from <sugar_root>/custom/modulebuilder/packages/Event_Manager/modules/<module>/relationships.php

if ( $this->_focus->account_type  !=  'FacilitatorCo'  &&  $this->_focus->account_type  !=  'Venue'  &&  $this->_focus->account_type  !=  'Caterer'   )
if ($this->_focus->account_type  !=  'Venue'  &&  $this->_focus->account_type  !=  'Caterer'   )

Rebuild and Repair

Note that the inclusion of the unset for cases and bugs is just there to ensure the code is working - and it does for cases and bugs.

Cases and bugs properly hide when the Account Type is NOT one of the types defined.
The custom subpanel continues to display regardless of the Account Type selected and saved.

I assumed the issue must be me using the incorrect name for the Events subpanel, but I did a var_dump from within view.detail using the _displaySubPanels() function and I was using the correct name (evmgr_evs_accounts) as created by Module Builder.  I also checked the layoutdefs file at (sugar_root)/custom/Extension/modules/Accounts/Ext/Layoutdefs/evmgr_evs_accounts_Accounts.php and it had
// created: 2014-02-17 16:31:16
$layout_defs["Accounts"]["subpanel_setup"]['evmgr_evs_accounts'] = array (
  'order' => 10,
  'module' => 'EvMgr_Evs',
  'subpanel_name' => 'default',
  'sort_order' => 'asc',
  'sort_by' => 'id',
  'get_subpanel_data' => 'evmgr_evs_accounts',
  'top_buttons' =>
  array (
    0 =>
    array (
      'widget_class' => 'SubPanelTopButtonQuickCreate',
    1 =>
    array (
      'widget_class' => 'SubPanelTopSelectButton',
      'mode' => 'MultiSelect',

which confirmed I am using the correct name.

The evmgr_evs_accounts subpanel does show so it is being defined, but it will not unset.

I also noted that when I edited the order variable and set it to 10 (which should move the subpanel high on the detaiview), it did not change the location of the evmgr_evs_accounts subpanel.

Does anyone know why the custom subpanel will not unset but the core subpanels will?