Adding panels to editviewdefs.php via manifest file

蓝咒 提交于 2019-11-29 12:49:29

You're after the ParserFactory class, which can be used from a post_install or similar script executed as your module/package is installed. My understanding is that ParserFactory will call custom files if they're there, or stock files and adjust them appropriately and safely if not.

In your module's directory, create a subdirectory called 'scripts' and create 'post_install.php' which contains a single function post_install(). Your package dir will look something like this:

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

You use the ParserFactory like this:

<?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);

};

Bingo - and Thank you to Matthew

I did not know where to find this and on the Sugar forum, no-one seemed to know so thank you Matthew.

So yes, it is very easy to add panels to an existing module in SugarCRM using the code that Matthew pointed out

To add a Panel called Events, in

/custom/modules/Accounts/language/en_us.lang.php

(add to this or create new file if you prefer)

add

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

and then in the post_install.php file in the /scripts directory of the install package put

<?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;
}
?>

(I have just put two existing fields in the new panel but you can just as easily place newly created fields (from the manifest file) into the new panel as well

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!