HOWTO: Add a subpanel using code

sugarcrmdevelopers —  May 18, 2011 — 5 Comments

I thought I would build upon this week’s earlier example of how to add a flex relate by showing how to add the related subpanels as well. If you remember, we’ve added a new module named test_flexparent, which relates to either the Contacts or Leads module. In order to setup subpanels to show related test_flexparent records in the detail views of the Contacts and Leads modules, you’ll just need to add the subpanel definitions for each module. Let’s look how for the Contacts module.

First, we need to add a link field that handles the relationship, just like we did in the previous post on the test_flexparent module side. To do this, add in a file named custom/Extension/modules/Contacts/Ext/Vardefs/flexrelate.php with the following contents:

Now, we just need to define the subpanel. Just add the following contents into a file named custom/Extension/modules/Contacts/Ext/Layoutdefs/forflexrelate.php:

Lastly, we just need to add a language string for the subpanel’s title. Make a new file named custom/Extension/modules/Contacts/Ext/Language/en_us.flexrelate.php with the following contents to do so.

Now, just do a Quick Rebuild and Repair and the subpanel should appear in the Contacts detailview. The procedure is the same for the Leads module, just exchange the Contact references for Leads ones and you should be all good to go.

5 responses to HOWTO: Add a subpanel using code

  1. 

     The Code Content link is dead.  Please fix it thx

  2. 

    Hi.
    This doesn’t work in 6.5.17 PE.
    When I do this I get an sql error in logfile:
    09/30/14 08:34:54 [604][1][FATAL] Error running count query for Contact List: Query Failed: ( SELECT count(*) c FROM test_flexparent LEFT JOIN test_flexparent_cstm ON test_flexparent.id = test_flexparent_cstm.id_c INNER JOIN contacts test_flexparent_rel ON test_flexparent.parent_id=test_flexparent_rel.id AND test_flexparent_rel.deleted=0
    AND contacts.parent_type = ‘Contacts’
    where ( test_flexparent.parent_id=’4a256342-fa8d-dc14-a8cc-53071c3ae00d’) AND test_flexparent.deleted=0 ): MySQL error 1054: Unknown column ‘contacts.parent_type’ in ‘on clause’

    And the subpanel isn’t displayed.

    any idea?

    regards robert

  3. 

    How do I add the same subpanel definition to a module builder package? Using the Ext directory is fine, and works, but this does not survive situations where the module is deployed again? I have tried using the manifest.php file to move the separate files into position in the deployed destination directory but this gets overwritten when the module is deployed.

    I was thinking of using the subpanels folder and adding a new file, but it uses slightly different terminology and I cant work out what goes where. Basically need to map the separate file contents:

    $layout_defs[‘clt_client_profile’][‘subpanel_setup’][‘clt_module_doc_item’] = array(
    ‘order’ => 130,
    ‘module’ => ‘clt_client_doc_item’,
    ‘get_subpanel_data’=>’clt_module_doc_item’,
    ‘sort_order’ => ‘asc’,
    ‘sort_by’ => ‘name’,
    ‘subpanel_name’ => ‘default’,
    ‘title_key’ => ‘lbl_clt_module_doc_item’,
    array (
    0 =>
    array (
    ‘widget_class’ => ‘SubPanelTopButtonQuickCreate’,
    ),
    1 =>
    array (
    ‘widget_class’ => ‘SubPanelTopSelectButton’,
    ‘mode’ => ‘MultiSelect’,
    ),
    ),
    );

    To something along the lines of:

    array (
    0 =>
    array (
    ‘widget_class’ => ‘SubPanelTopCreateButton’,
    ),
    1 =>
    array (
    ‘widget_class’ => ‘SubPanelTopSelectButton’,
    ‘popup_module’ => ‘clt_client_documentation_item’,
    ),
    ),
    ‘where’ => ”,
    ‘list_fields’ =>
    array (
    ‘client_type’ =>
    array (
    ‘type’ => ‘enum’,
    ‘default’ => true,
    ‘studio’ => ‘visible’,
    ‘vname’ => ‘LBL_CLIENT_TYPE’,
    ‘width’ => ‘30%’,
    ),
    ‘date_entered’ =>
    array (
    ‘type’ => ‘datetime’,
    ‘vname’ => ‘LBL_DATE_ENTERED’,
    ‘width’ => ‘15%’,
    ‘default’ => true,
    ),
    ‘date_modified’ =>
    array (
    ‘vname’ => ‘LBL_DATE_MODIFIED’,
    ‘width’ => ‘15%’,
    ‘default’ => true,
    ),
    ‘edit_button’ =>
    array (
    ‘vname’ => ‘LBL_EDIT_BUTTON’,
    ‘widget_class’ => ‘SubPanelEditButton’,
    ‘module’ => ‘clt_client_documentation_item’,
    ‘width’ => ‘4%’,
    ‘default’ => true,
    ),
    ‘remove_button’ =>
    array (
    ‘vname’ => ‘LBL_REMOVE’,
    ‘widget_class’ => ‘SubPanelRemoveButton’,
    ‘module’ => ‘clt_client_documentation_item’,
    ‘width’ => ‘5%’,
    ‘default’ => true,
    ),
    ),
    );

    • 

      My recommendation is that once you start making customizations to a Module Builder created package that you stop using Module Builder to work on the package and make further customizations manually.

      You can run into issues even with Sugar Studio changes to Custom Modules deployed using Module Builder because those changes are lost when the Custom Module gets re-deployed using Builder.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s