【问题标题】:Adding panels to editviewdefs.php via manifest file通过清单文件将面板添加到 editviewdefs.php
【发布时间】:2014-01-29 22:34:08
【问题描述】:

SugarCRM installable changes in detailview 问题是关于如何添加面板,使用模块安装程序的清单文件添加到现有模块的编辑视图/详细信息视图,而不会清除以前在自定义目录中进行的自定义。

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

我知道您可以使用从清单文件中调用的 post_execute 函数来编辑 /自定义/模块//元数据/ 目录,但这涉及对这些文件中已经存在的内容进行一些猜测。

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

【问题讨论】:

    标签: sugarcrm


    【解决方案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);
    
    };
    

    【讨论】:

    • 马修,很抱歉延迟回复;这看起来不错,但我无法让脚本通过 parser = ParserFactory::getParser('detailview', 'Accounts');线。我在 post_install.php 文件中找到了 post_install 函数。我使用了您拥有的确切行(复制了它),但它挂在那里。有什么建议吗?
    • SugarCRM.log 或 PHP 错误日志中有什么内容吗?也许你需要需要类文件。
    【解决方案2】:

    宾果游戏 - 感谢马修

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

    所以是的,使用 Matthew 指出的代码将面板添加到 SugarCRM 中的现有模块非常容易

    要添加一个名为事件的面板,在

    /custom/modules/Accounts/language/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;
    }
    ?>
    

    (我刚刚在新面板中放置了两个现有字段,但您也可以轻松地将新创建的字段(来自清单文件)放入新面板中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-08
      • 2019-05-22
      • 2012-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多