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

时间:2015-03-02 11:11:35

标签: sugarcrm

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

$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];
                }
            }
        }
    }
}

但我认为应该有一些原生的东西。请你能给我一些建议吗?

1 个答案:

答案 0 :(得分:9)

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

$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();
}