【发布时间】:2019-03-08 21:56:32
【问题描述】:
在 Suitecrm/SugarCRM 6.5 中
我需要修改 ListView。根据特定条件显示字段的值。
在帐户模块中,name 字段根据某些条件可能为空,我要求在发生这种情况时显示自定义字段的值。为此,首先我在编辑/细节视图中像往常一样尝试使用“customCode”+ smarty,但在几篇文章中提到这在 ListView 中是不可能的。让步是使用逻辑钩子 + 一个非 db 字段来存储计算的字段。按照这个 SO answer 我写了以下内容:
custom/Extension/modules/Accounts/Ext/Vardefs/custom_field_name_c.php 的自定义字段
<?php
$dictionary['Account']['fields']['name_c']['name'] = 'account_name_c';
$dictionary['Account']['fields']['name_c']['vname'] = 'LBL_ACCOUNT_NAME_C';
$dictionary['Account']['fields']['name_c']['type'] = 'varchar';
$dictionary['Account']['fields']['name_c']['len'] = '255';
$dictionary['Account']['fields']['name_c']['source'] = 'non-db';
$dictionary['Account']['fields']['name_c']['dbType'] = 'non-db';
$dictionary['Account']['fields']['name_c']['studio'] = 'visible';
标签suitecrm/custom/Extension/modules/Accounts/Ext/Language/es_ES.account_name_c.php
<?php
$mod_strings['LBL_ACCOUNT_NAME_C'] = 'Nombre de cuenta';
custom/modules/Accounts/logic_hooks.php 处的逻辑挂钩条目
$hook_array['process_record'] = Array();
$hook_array['process_record'][] = Array(
2,
'Get proper name',
'custom/modules/Accounts/hooks/ListViewLogicHook.php',
'ListViewLogicHook',
'getProperName'
);
custom/modules/Accounts/hooks/ListViewLogicHook.php 处的逻辑钩子
<?php
class ListViewLogicHook
{
public function getProperName(&$bean, $event, $arguments)
{
if (empty($bean->fetched_row['name'])) {
$bean->account_name_c = $bean->fetched_row['person_name_c'];
} else {
$bean->account_name_c = $bean->fetched_row['name'];
}
// Here I also tried, but same result
// $bean->account_name_c = empty($bean->name) ? $bean->person_name_c : $bean->name;
}
}
listviewdefs.php custom/modules/Accounts/metadata/listviewdefs.php
我添加了字段
'NAME_C' =>
array (
'width' => '20%',
'label' => 'LBL_ACCOUNT_NAME_C',
'default' => true,
),
在这些修改和修复之后,我希望看到该字段充满正确的值。但它似乎是空的。我已经验证逻辑钩子被正确调用,但name 和person_name_c 字段始终为空。如果相关,我已经在 Studio 中验证了 Account 中的 name 字段是 typename 我不知道在获取其值时这意味着什么。
感谢你的cmets
【问题讨论】: