Hello everyone,
I’m customizing the Products subpanel in the Clienti module so that, when the Edit button is clicked, it redirects to the cstm_ClienteProdotto module (which acts as a bridge between the two) instead of going to the AOS_Products module. This approach is explained in the following video:
https://www.youtube.com/watch?v=KYVhQx21ugk&t=374s
Host module cstm_Clienti
suitecrm\public\legacy\custom\Extension\modules\cstm_Clienti\Ext\Layoutdefs\cstm_clienti_aos_products_1_cstm_Clienti.php :
$layout_defs["cstm_Clienti"]["subpanel_setup"]['cstm_clienti_aos_products_1'] = array (
'order' => 100,
'module' => 'AOS_Products',
'subpanel_name' => 'customSubPanel',
'sort_order' => 'asc',
'sort_by' => 'id',
'title_key' => 'LBL_CSTM_CLIENTI_AOS_PRODUCTS_1_FROM_AOS_PRODUCTS_TITLE',
'get_subpanel_data' => 'cstm_clienti_aos_products_1',
'top_buttons' =>
array (
/*
0 =>
array (
'widget_class' => 'SubPanelTopButtonQuickCreate',
),
*/
0 =>
array (
'widget_class' => 'SubPanelTopSelectButton',
'mode' => 'MultiSelect',
),
),
);
Sub Module AOS_Products
suitecrm\public\legacy\custom\modules\AOS_Products\metadata\subpanels\customSubPanel.php :
if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}
$module_name='AOS_Products';
$subpanel_layout = array(
'top_buttons' => array(
array('widget_class' => 'SubPanelTopCreateButton'),
array('widget_class' => 'SubPanelTopSelectButton', 'popup_module' => $module_name),
),
'where' => '',
'list_fields' => array(
'name'=>array(
'vname' => 'LBL_NAME',
'widget_class' => 'SubPanelDetailViewLink',
'width' => '45%',
),
'date_modified'=>array(
'vname' => 'LBL_DATE_MODIFIED',
'width' => '45%',
),
'edit_button'=>array(
'widget_class' => 'SubPanelEditClienteProdottoButton',
'module' => 'cstm_ClienteProdotto',
'width' => '4%',
),
/*
'remove_button'=>array(
'widget_class' => 'SubPanelRemoveButton',
'module' => $module_name,
'width' => '5%',
),
*/
),
);
I can confirm that customSubPanel
is being used, because the remove_button does not appear. However, when I click the Edit button, it still loads the normal AOS_Products edit view instead of calling my custom SubPanelEditClienteProdottoButton
class.
My custom class is located here:
suitecrm\public\legacy\custom\include\generic\SugarWidgets\SugarWidgetSubPanelEditClienteProdottoButton.php
class SugarWidgetSubPanelEditClienteProdottoButton extends SugarWidgetField
{
protected static $defs = array();
protected static $edit_icon_html;
public function displayHeaderCell($layout_def)
{
return '';
}
public function displayList(&$layout_def)
{
global $app_strings;
global $subpanel_item_count;
// Genera un ID unico per il bottone
$unique_id = $layout_def['subpanel_id'] . "_edit_" . $subpanel_item_count;
// Recupera gli ID: il cliente dall'url e il prodotto dal layout_def
$cliente_id = $_REQUEST['record'];
$prodotto_id = $layout_def['fields']['id'];
// Sanifica gli input per la query
$cliente_id = $GLOBALS['db']->quote($cliente_id);
$prodotto_id = $GLOBALS['db']->quote($prodotto_id);
// Costruisci la query corretta
$sql = "SELECT A.id
FROM cstm_clienteprodotto AS A
JOIN cstm_clienteprodotto_cstm AS B ON A.id = B.id_c
WHERE B.cliente_id_c = {$cliente_id}
AND B.prodotto_id_c = {$prodotto_id}
AND A.deleted = 0";
$result = $GLOBALS['db']->query($sql);
$row = $GLOBALS['db']->fetchByAssoc($result);
$href = 'index.php?module=cstm_ClienteProdotto'
. '&action=EditView'
. '&record=' . $row['id']
. '&return_module=' . $_REQUEST['module']
. '&return_action=DetailView'
. '&return_id=' . $_REQUEST['record'];
$handler = '';
if ($layout_def['ListView']) {
return '<a href="' . $href . '" onmouseover="' . $handler . '" onfocus="' . $handler .
'" class="listViewTdToolsS1" id="' . $unique_id . '">' . $app_strings['LNK_EDIT'] . '</a>';
}
return '';
}
}
What I Have Already Tried:
- Performed a Quick Repair & Rebuild multiple times.
- Deleted the cache in
suitecrm/cache/
. - Checked the logs (
suitecrm.log
,suitecrm/logs/prod/prod.log
andPHP error logs
), but there are no references to this issue.
Has anyone encountered a similar issue, or can anyone point me in the right direction on why my custom edit button logic isn’t being applied?
Thank you in advance!