How to create a custom view of type Edit in SugarCRM CE 6.5 or SuiteCRM

Written Monday July 08 2019

In SugarCRM CE 6.5 or in SuiteCRM there is the standard EditView mask that allows you to insert/modify an object of a specific module, there is also the QuickCreate that can be used to quickly insert an object.

These two masks are standard and easy to manage with Studio.

Sometimes, however, it can be useful to create a custom view of type Edit to manage personalized insert/modify to be used in specific cases.

To obtain this you need 3 steps:

  1. create the view in custom/modules/<module_name>/views/view.<view_name>.php;
  2. activate the view within the custom/modules/<module_name>/controller.php;
  3. define the view in custom/modules/<module_name>/metadata/<view_name>viewdefs.php.

After a “Quick Repair and Rebuild“, you are allowed to call the view with a link like this <crmurl>/index.php?module=<module_name>&action=<view_name>&record=<objectid> eventually followed with other parameters you may need (managed in the file view.<view_name>.php).

Let’s start with the file custom/modules/<module_name>/views/view.<view_name>.php:

<?php
if (! defined('sugarEntry') || ! sugarEntry)
    die('Not A Valid Entry Point');

class <module_name>View<view_name> extends ViewEdit {
    public function preDisplay() {
        $this->type = '<view_name>';
        parent::preDisplay();
        $this->ev->view = '<view_name>View';
    }

    public function display() {
        parent::display();
    }
}
?>

Let’s examine the file custom/modules/<module_name>/controller.php:

<?php
if (! defined('sugarEntry') || ! sugarEntry)
    die('Not A Valid Entry Point');

class <module_name>Controller extends SugarController {
    public function action_<view_name>() {
        $this->view = '<view_name>';
    }
}
?>

Finally the file custom/modules/<module_name>/metadata/<view_name>viewdefs.php that will have the same syntax of the file custom/modules/<module_name>/metadata/​editviewdefs.php​:

<?php
$module_name = '<module_name>';
$_object_name = '<object_name>';
$viewdefs [$module_name] = array (
    'EditView' => array (
        'templateMeta' => array (
            'form' => array (
                 'buttons' => array (
                    0 => 'SAVE',
                    1 => 'CANCEL',
                ),
                'headerTpl' => 'include/EditView/header.tpl',
                'footerTpl' => 'include/EditView/footer.tpl',
            ),
            'maxColumns' => '2',
            'widths' => array (
                0 => array (
                    'label' => '10',
                    'field' => '30',
                ),
                1 => array (
                    'label' => '10',
                    'field' => '30',
                ),
            ),
            'useTabs' => false,
            'tabDefs' => array (
                'DEFAULT' => array (
                    'newTab' => false,
                    'panelDefault' => 'expanded',
                ),
            ),
        ),
        'panels' => array (
            'default' => array (
                0 => array (
                    0 => 'name'
                ),
            ),
        ),
    ),
);
?>

In this example we put only the field “name”, but of course you can set it similarly to the file custom/modules/<modulename>/metadata/​editviewdefs.php​.

In this examples:

  1. <module_name> means the module name you see in the URL, for example, Contacts, Leads, Accounts, etc.
  2. <view_name> means the view name like editview, detailview, etc
  3. <object_name> means the object name, the name of the module in the database, for example, contacts, leads, accounts, etc.

Problems? Contact us for professional advices on SugarCRM CE or SuiteCRM.