How to create a custom view of type Edit in SugarCRM / SuiteCRM

In SugarCRM / 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 with 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​.

Note :

1. Here, <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 module name you see in the URL, for example, Contacts, Leads, Accounts, etc.

Hope you find this blog post helpful.

Feel free to add comments and queries, that helps us to improve the quality of posts.

You can contact us at info@infotechbuddies.com

Thank you.

Spread the love

2 thoughts on “How to create a custom view of type Edit in SugarCRM / SuiteCRM

Leave a Reply

Your email address will not be published. Required fields are marked *