SugarCRM 如何获取所有模块字段的详细信息列表

SugarCRM how to get all module fields list with details

我正在开发自定义模块,它需要获取所有字段的列表以及其他模块的详细信息(关系、其他属性)。当我使用其他开发人员自定义模块时出现问题。我用了

$dictionary

但并非所有模块字段都存在。然后我破解了

require_once 'modules/ModuleBuilder/views/view.modulefields.php';
$viewmodfields = new ViewModulefields();
$objectName = BeanFactory::getObjectName($module);
VardefManager::loadVardef($module, $objectName, true);
global $dictionary;

$fieldsData = array();
foreach($dictionary[$objectName]['fields'] as $def) {
   if ($viewmodfields->isValidStudioField($def)){
        $mod_field = array();
        $mod_field['name'] = $def['name'];
        $mod_field['label'] = translate($def['vname'], $module);
        }
    }
}

还有更残酷的事情:

$fieldData = array();

$views = array(MB_EDITVIEW, MB_DETAILVIEW, MB_QUICKCREATE);

// Normlize data
foreach($views as $view) {
   // Get module panels and fields by view
   $parser = ParserFactory::getParser($view, $module);
   $panels = $parser->_viewdefs['panels'];
   $fields = $parser->_fielddefs;

    foreach($panels as $panelName => $panelData) {
        foreach($panelData as $panelDataItem) {
            foreach($panelDataItem as $fieldName) {
                // Check if block field name exists in field array
                if( isset($fields[$fieldName]) ) {
                    // Set unique name in array (name can be in editview and detailview)
                    $fieldData[$fields[$fieldName]['name']] = $fields[$fieldName];
                }
            }
        }
    }
}

但我认为应该有更原生的东西。可以请你给我建议吗?

遍历全局 $moduleList 数组以获取所有模块名称并使用 BeanFactory::getBean 为该模块获取一个空对象,并使用 getFieldDefinitions 检索该模块的字段定义:

$module_list = array_intersect($GLOBALS['moduleList'],array_keys($GLOBALS['beanList']));

foreach($module_list as $module_name) {
        $bean = BeanFactory::getBean($module_name);
        $field_defs[$module_name] = $bean->getFieldDefinitions();
}