2014-01-29 21 views
1

SugarCRM installable changes in detailview 有人问及如何添加面板,使用Module Installer的清单文件添加到现有模块的editview/detailview而不清除以前定制在自定义目录中创建。通过清单文件将面板添加到editviewdefs.php

答案提供了如何添加字段,但不是面板。

我知道你可以使用来自清单文件,称为post_execute功能在 /自定义/模块//元/ 目录编辑editviewdefs.php和detailviewdefs.php文件,但需要做出什么一些猜测已经存在于这些文件中。

有谁知道如何通过清单文件(或post_execute)增加面板,增量面板,而无需使用PHP代码手动编辑editviewdefs.php和detailviewdefs.php文件?

回答

1

您在ParserFactory类之后,可以使用post_install或类似的脚本来执行安装的模块/软件包。我的理解是,ParserFactory将调用自定义文件(如果它们在那里),或者存储文件并在适当的情况下进行调整,否则就会安全地进行调整。

在您的模块目录中,创建一个名为'scripts'的子目录并创建包含单个函数post_install()的'post_install.php'。你的包目录将是这个样子:

~$ find . 
/LICENSE.txt 
/manifest.php 
/scripts/post_install.php 

你这样使用ParserFactory:

<?php 
function post_install(){ 

// $parser becomes an associative array for the metadata, similar to editviewdefs.php 
require_once('modules/ModuleBuilder/parsers/ParserFactory.php'); 
$parser = ParserFactory::getParser('detailview', 'Accounts'); 

// finding the panels (which contain their fields), you can 
// now add fields or additional arrays to this array, creating new panels 
// (you could manipulate $parser->_viewdefs directly, but I find this easier) 
$panels = array_keys ($parser->_viewdefs [ 'panels' ]); 

// place your panels back into the $parser and save 
$parser->_viewdefs['panels'] = $panels; 
$parser->handleSave(false); 

}; 
+0

马修,对不起,延迟响应;这看起来不错,但我无法让脚本通过解析器= ParserFactory :: getParser('detailview','Accounts');线。我到了post_install.php文件中的post_install函数。我用了你的确切线(复制它),但它挂在那里。有什么建议么? – Ramblin

+0

SugarCRM.log或PHP错误日志中的任何内容?也许你需要要求类文件。 –

+0

http://support.sugarcrm。com/02_Documentation/04_Sugar_Developer/Sugar_Developer_Guide_6.7/03_Module_Framework/02_Metadata/Examples/Manipulating_Layouts_Programmatically this example have the details details。 –

1

宾果 - 和谢谢马修

我不知道在哪里可以找到这一点,在Sugar论坛上,没有人似乎知道,所以谢谢马修。

所以,是的,这是非常容易使用,马修指出

添加一个名为事件面板中的代码SugarCRM的面板添加到现有的模块,在

/自定义/模块/会计/语言/ en_us.lang.php

(添加到这个或创建新的文件,如果你喜欢)

添加

$mod_strings = array ('LBL_DETAILVIEW_PANEL1' => 'Events',); 

,然后在安装包的/ scripts目录中的文件post_install.php把

<?php 

function post_install() 
{ 
    // Debug point - checking to see if get to post_install script 
    echo "Made it to the post_install script.<br />"; 

    // Use the ParserFactory to edit the view arrays 
    // Fetch the existing view into an array called $view_array 
    require_once('modules/ModuleBuilder/parsers/ParserFactory.php'); 
    $view_array = ParserFactory::getParser('detailview','Accounts'); 
    // Declare the additional content 
    $new_content = array 
    (
     0 => array 
     (
      0 => array 
      (
       'name' => 'created_by_name', 
       'label' => 'LBL_CREATED', 
      ), 
      1 => array 
      (
       'name' => 'modified_by_name', 
       'label' => 'LBL_MODIFIED_NAME', 
      ), 
     ), 
    ); 
    // Add the new content to the desired section of the view array 
    $view_array->_viewdefs['panels']['lbl_detailview_panel1'] = $new_content; 
    //Save the layout 
    $view_array->handleSave(false); 

    return; 
} 
?> 

(我刚刚把现有的两个领域在新的面板,但你可以很容易地将新创建的域(从清单文件)到新的面板以及