How to customize the display of any field in SubPanels
In SugarCRM CE 6.5 or in SuiteCRM, the way fields are displayed in SubPanels, follows more or less the same rules as displaying them in ListView, but sometimes it's useful to be able to see certain fields in a unique, non-standard way.
In this article, I'll show you how to create a completely customizable display of any field in a SubPanel.
I've found that it's possible to change the way a field is displayed in SubPanels by redefining the default "widget" that displays it. This is completely Upgrade-Safe (i.e., as a standard customization that won't be lost if you upgrade to a SugarCRM CE or SuiteCRM release).
In the file that defines the SubPanel for a given module, for example in custom\modules\<module_name>\metadata\subpanels\<subpanel_name>.php, we can change the widget responsible for displaying a given field, specifically using the SubPanelDetailViewLink widget, which was created to display the field as a link to the DetailView of a given object. This widget is normally used for Relate or Flex Relate or Parent fields or for the Name field, but we'll use it to create the display we want.
In addition to this, we add our own parameter to indicate the type of visualization we want to obtain.
Here is an example:
'parent_type' => array(
'name' => '<field_name>',
'vname' => 'LBL_QUOTE',
'widget_class' => 'SubPanelDetailViewLink',
'custom_type' => 'show_quote',
'width' => '10%',
'sortable' => false,
),
In this code snippet, we've changed the "widget_class" parameter to refer to the widget we'll customize and added the "custom_type" parameter to indicate how we want to display this field <field_name>.
Now let's copy the file include\generic\SugarWidgets\SugarWidgetSubPanelDetailViewLink.php into custom\include\generic\SugarWidgets\SugarWidgetSubPanelDetailViewLink.php, to carry out our customization.
At the top of the public function displayList(&$layout_def) method, we will place the management of our particular view, taking care to check the "custom_type" parameter (and leaving the rest of the following code unchanged):
public function displayList(&$layout_def) {
if (! empty($layout_def['custom_type'])) {
$bean = BeanFactory::getBean($layout_def['module'], $layout_def['fields']['ID']);
switch ($layout_def['custom_type']) {
case 'show_quote':
return '<whatever_we_want>';
}
}Here we checked if the "custom_type" parameter is present, if so, we can retrieve the bean we are displaying via $layout_def['module'] and $layout_def['fields']['ID'] and then if the requested display type is "show_quote", as we specified in the subpanel definition, in the "custom_type" parameter.
Naturally, we can add other "case" to the "switch" to manage other particular views, always based on our "custom_type" parameter.
After a “Quick Repair and Rebuild“, our "trick" should work!
In this examples:
- <module_name> means the module name you see in the URL, for example, Contacts, Leads, Accounts, etc.
- <view_name> means the view name like editview, detailview, etc
- <field_name> indicates the name of the field to whose display we are customizing.
- <whatever_we_want>: indicates the point where to insert our custom view, taking into account that here we have the $bean object available which refers to the bean displayed in this row of the SubPanel.
Problems? Contact us for professional advices on SugarCRM CE or SuiteCRM.