SlideShare a Scribd company logo
4/14/10©2010 SugarCRM Inc. All rights reserved.1
Best Practices for Creating Custom Apps in Sugar	John MerticSugarCRM4/14/10©2010 SugarCRM Inc. All rights reserved.2
The golden rules of customizationsUse Module Builder/Studio for customizations if possibleOtherwise, put your code inside the custom directory4/14/10©2010 SugarCRM Inc. All rights reserved.3
Why do this?Module Builder/Studio changes are well supported and easier to manageCustomizations are separated from the shipped codeAllows you to manage your customizations via version control ( SVN, Git, etc )Files in here aren’t disturbed by any Sugar upgradesException – sometimes we will try to fix metadata templates on upgrades for new/removed fields.	Makes your app “Upgrade Safe”4/14/10©2010 SugarCRM Inc. All rights reserved.4
Exceptions to this…New modules need to be under modules/ directory.Bean class customizations to OOTB modules need to be on the original bean file.We’ll look at using logic hooks and other techniques to avoid this for many use cases.Will need to manually manage this during upgrades, so best to avoid.4/14/10©2010 SugarCRM Inc. All rights reserved.5
Let’s see what we can do4/14/10©2010 SugarCRM Inc. All rights reserved.6
MVC FrameworkMVC stands for Model View Controller4/14/10©2010 SugarCRM Inc. All rights reserved.7
MVC Framework – The anatomy of a request4/14/10©2010 SugarCRM Inc. All rights reserved.8
MVC Framework – SugarApplicationBootstraps the applicationLoads many of the default application settingsLanguageThemeSessionHandles User AuthenticationLoads the controller4/14/10©2010 SugarCRM Inc. All rights reserved.9
MVC Framework - SugarControllerManages all the actions of a moduleContains logic for handling requests that don’t require a viewExample: Record savingMaps all other requests to the correct viewLogic for mapping an action of one name to a view of anotherCan detect if we should be using MVC or classic views4/14/10©2010 SugarCRM Inc. All rights reserved.10
MVC Framework – SugarController API4/14/10©2010 SugarCRM Inc. All rights reserved.11
MVC Framework – Controller Example4/14/10©2010 SugarCRM Inc. All rights reserved.12<?phpclass ExampleController extends SugarController{    public function action_hello()    {        echo "Hello World!";    }    public function action_goodbye()    {        $this->view = 'goodbye';    }}
MVC Framework – Controller-less mappingIf your module doesn’t need to have any controller logic, use action mapping insteads.Create file named action_view_map.php with the following contents:4/14/10©2010 SugarCRM Inc. All rights reserved.13<?php$action_view_map['goodbye'] = 'goodbye';
MVC Framework - SugarViewContains the display logic for the actionUses a metadata backend for Edit, Detail, List, Popup viewsAnd Convert Lead in Sugar 6.0For other views, you write the code for the view and put it in modules/modulename/views/view.viewname.php4/14/10©2010 SugarCRM Inc. All rights reserved.14
MVC Framework – SugarView API4/14/10©2010 SugarCRM Inc. All rights reserved.15
MVC Framework – SugarView API4/14/10©2010 SugarCRM Inc. All rights reserved.16
MVC Framework – View Example4/14/10©2010 SugarCRM Inc. All rights reserved.17<?phpclass ViewExample extends SugarView{    public function preDisplay()    {        if ( !is_admin($GLOBALS["current_user"]) )sugar_die("Not an Admin");    }    public function display()    {        echo "Hello Admin!";    }}
MVC Framework – ViewDetail Example4/14/10©2010 SugarCRM Inc. All rights reserved.18<?phprequire_once('include/MVC/View/views/view.detail.php');class ContactsViewDetail extends ViewDetail{ 	public function display()  	{ 	    $admin = new Administration(); 	    $admin->retrieveSettings();if(isset($admin->settings['portal_on'])  	            && $admin->settings['portal_on']) { 	        $this->ss->assign("PORTAL_ENABLED", true);           }parent::display(); 	}}
4/14/10©2010 SugarCRM Inc. All rights reserved.19Where do I put my customizations?Controllers/custom/modules/Modulename/controller.phpclass CustomModulenameController extends SugarControllerViews/custom/modules/Modulename/views/view.viewname.phpclass CustomModulenameViewViewname extends ModulenameViewViewnameIf that class doesn’t exist extend from ViewViewname or SugarView
Metadata Layer4/14/10©2010 SugarCRM Inc. All rights reserved.20
Kinds of metadataeditviewdefs.php / detailviewdefs.php / quickcreatedefs.phpWireless variants: wireless.editviewdefs.php, wireless.detailviewdefs.phpsubpaneldefs.phplistviewdefs.phpwireless.listviewdefs.phpsearchdefs.phpwireless.searchdefs.phpSearchFields.phppopupdefs.php4/14/10©2010 SugarCRM Inc. All rights reserved.21
editviewdefs.php4/14/10©2010 SugarCRM Inc. All rights reserved.22<?php$viewdefs[$module_name]['EditView'] = array(    'templateMeta' => array(        'maxColumns' => '2',         'widths' => array(array('label' => '10', 'field' => '30'), array('label' => '10', 'field' => '30'),            ),                                                                                                                                            ),    'panels' =>array (        'default' =>             array (                array (                  'name',                  'assigned_user_name',                ), array(array(                  'name' => 'date_modified',                  'customCode' => '{$fields.date_modified.value} {$APP.LBL_BY} {$fields.modified_by_name.value}',                  'label' => 'LBL_DATE_MODIFIED',)),            ),            array(                array ( 'description',                ),            ),        ),                  );
subpaneldefs.php4/14/10©2010 SugarCRM Inc. All rights reserved.23<?php$layout_defs[$module_name] = array(     'subpanel_setup' => array(	'contacts' => array(		'order' => 20,		'module' => 'Contacts',		'sort_by' => 'last_name, first_name',		'sort_order' => 'asc',		'subpanel_name' => 'default',		'get_subpanel_data' => 'contacts',		'title_key' => 'LBL_CONTACTS_SUBPANEL_TITLE',		'top_buttons' => array(array('widget_class' => 'SubPanelTopButtonQuickCreate'),			array(				'widget_class'=>'SubPanelTopSelectButton',				'mode'=>'MultiSelect’			),		),	),    ),);
searchdefs.php4/14/10©2010 SugarCRM Inc. All rights reserved.24<?php$searchdefs[$module_name] = array(    'templateMeta' => array(        'maxColumns' => '3',        'widths' => array('label' => '10', 'field' => '30'),        ),    'layout' => array(        'basic_search' => array(            'name',array('name'=>'current_user_only', 'label'=>'LBL_CURRENT_USER_FILTER', 'type'=>'bool'),            ),        'advanced_search' => array(            'name',array('name' => 'phone', 'label' =>'LBL_ANY_PHONE', 'type' => 'name'),array('name' => 'address_city', 'label' =>'LBL_CITY', 'type' => 'name'),array('name' => 'email', 'label' =>'LBL_ANY_EMAIL', 'type' => 'name'),array('name' => 'assigned_user_id', 'type' => 'enum', 	      'label' => 'LBL_ASSIGNED_TO',                 'function' => array('name' => 'get_user_array', 	     		'params' => array(false))),        ),    ),);
SearchFields.php4/14/10©2010 SugarCRM Inc. All rights reserved.25<?php$searchFields[$module_name] = array (    'name' => array( 'query_type'=>'default'),    'current_user_only'=> array('query_type'=>'default',	'db_field'=>array('assigned_user_id'),'my_items'=>true, 	'vname' => 'LBL_CURRENT_USER_FILTER', 'type' => 'bool'),    'assigned_user_id'=> array('query_type'=>'default'),);
popupdefs.php4/14/10©2010 SugarCRM Inc. All rights reserved.26<?phpglobal $mod_strings;$popupMeta = array(    'moduleMain' => 'Account',    'varName' => 'ACCOUNT',    'orderBy' => 'name',    'whereClauses' => array(        'name' => 'accounts.name',         'billing_address_city' => 'accounts.billing_address_city',        'phone_office' => 'accounts.phone_office'),    'searchInputs' => array('name', 'billing_address_city', 'phone_office'),    'create' => array(        'formBase' => 'AccountFormBase.php',        'formBaseClass' => 'AccountFormBase',        'getFormBodyParams' => array('','','AccountSave'),        'createButton' => $mod_strings['LNK_NEW_ACCOUNT’]),    'listviewdefs' => array(        'NAME' => array(            'width' => '40', 'label' => 'LBL_LIST_ACCOUNT_NAME', 'link' => true,'default' => true,),         ),    'searchdefs'   => array(        'name', array('name' => 'assigned_user_id', 'label'=>'LBL_ASSIGNED_TO', 'type' => 'enum', 'function' => array('name' => 'get_user_array', 'params' => array(false))),        ),);
Where do I put my customizations?Subpaneldefscustom/Extension/modules/Modulename/Ext/Layoutdefs/NameWhateverYouWant.phpNeed to run ‘Quick Repair and Rebuild’ after changes are madeEverything else/custom/modules/Modulename/metadataWatch for Studio blowing out your changes.4/14/10©2010 SugarCRM Inc. All rights reserved.27
Logic Hooks4/14/10©2010 SugarCRM Inc. All rights reserved.28
Logic Hook Types4/14/10©2010 SugarCRM Inc. All rights reserved.29
Logic Hook Types (cont)4/14/10©2010 SugarCRM Inc. All rights reserved.30
Logic Hook Types (new in 6.0)4/14/10©2010 SugarCRM Inc. All rights reserved.31
logic_hooks.php4/14/10©2010 SugarCRM Inc. All rights reserved.32<?php$hook_version = 1; $hook_array = Array(); $hook_array['before_save'] = Array(); $hook_array['before_save'][] = Array(1, 'AccountHooks', 'custom/Accounts/AccountHooks.php','AccountHooks', 'getParentAccountIndustry'); Parameters for Logic Hook DefinitionParameter 1 - Sorting index used to sort the arrays of logic hook definitions before they are processed.Parameter 2 - A string value to identify the hookParameter 3 - Path to the PHP file to include which contains your logic hook codeParameter 4 - Name of the PHP class the logic hook method is inParameter 5 - Name of the PHP method to call
AccountHooks.php4/14/10©2010 SugarCRM Inc. All rights reserved.33<?phpclass AccountHooks{     public function getParentAccountIndustry( SugarBean $bean,          $event,          $arguments         )     {         if ( empty($bean->industry) 		 && !empty($bean->parent_id) ) {             $parentAccountFocus = new Account();             $parentAccountFocus->retrieve($bean->parent_id);             if ( !empty($parentAccountFocus->id) )                 $bean->industry = $parentAccountFocus->industry;         }     } }
Where do I put my customizations?Application Level Logic Hooks/custom/modules/Module Level Logic Hooks/custom/modules/Modulename/4/14/10©2010 SugarCRM Inc. All rights reserved.34
Themes4/14/10©2010 SugarCRM Inc. All rights reserved.35
Theme Directory Layoutcss/ - contains all css filesimages/ - contains all imagesjs/ - contains any js files.tpls/ - smarty templatesthemedef.php definition file.12/30/08©2009 SugarCRM Inc. All rights reserved.36
Themes can inherit from other themesTheme Inheritance Model12/30/08©2009 SugarCRM Inc. All rights reserved.37
Allow upgrade-safe modifications to themesAll themes can be modified by putting the replacement or overriding file in the custom/theme/<themename> directoryImage, HTML template file overrides are used as a replacement of the previous fileExample: an image custom/theme/<themename>/dog.gif would be used instead of theme/<themename>/dog.gif CSS and Javascript files are combined in order of inheritanceUses cssmin and jsmin to help reduce file sizeNo further code changes are required – changes are picked up automatically when themes cache is rebuilt.12/30/08©2009 SugarCRM Inc. All rights reserved.38
Resources4/14/10©2010 SugarCRM Inc. All rights reserved.39http://developers.sugarcrm.comBuy my book!
Thanks for coming!4/14/10©2010 SugarCRM Inc. All rights reserved.40

More Related Content

PPTX
WordPress 3 and You
PPT
Drupal Lightning FAPI Jumpstart
PPTX
Symfony 1, mi viejo amigo
PPTX
Forms in AngularJS
TXT
Jsp Notes
PDF
Curso Symfony - Clase 2
ODP
Best Practice Testing with Lime 2
PPT
Short Intro to PHP and MySQL
WordPress 3 and You
Drupal Lightning FAPI Jumpstart
Symfony 1, mi viejo amigo
Forms in AngularJS
Jsp Notes
Curso Symfony - Clase 2
Best Practice Testing with Lime 2
Short Intro to PHP and MySQL

What's hot (20)

ODP
Zend Framework 1.9 Setup & Using Zend_Tool
PPTX
Images and PWA in magento
PDF
Laying the proper foundation for plugin and theme development
PDF
How Can I tune it When I Can't Change the Code?
PPTX
Using of TDD practices for Magento
PPTX
AMD & Require.js
PDF
Bringing Characters to Life for Immersive Storytelling - Dioselin Gonzalez
PPT
What's new in Rails 2?
PPT
Krazykoder struts2 plugins
PPT
Nashvile Symfony Routes Presentation
PPTX
Bringing characters to life for immersive storytelling
PDF
Wordpress plugin development from Scratch
KEY
Rebooting TEI Pointers
PPT
Exploiting Php With Php
PDF
WordPress Queries - the right way
PPTX
Fixing Magento Core for Better Performance - Ivan Chepurnyi
PDF
Curso Symfony - Clase 3
DOCX
New tags in html5
PDF
購物車程式架構簡介
KEY
Unit testing with zend framework PHPBenelux
Zend Framework 1.9 Setup & Using Zend_Tool
Images and PWA in magento
Laying the proper foundation for plugin and theme development
How Can I tune it When I Can't Change the Code?
Using of TDD practices for Magento
AMD & Require.js
Bringing Characters to Life for Immersive Storytelling - Dioselin Gonzalez
What's new in Rails 2?
Krazykoder struts2 plugins
Nashvile Symfony Routes Presentation
Bringing characters to life for immersive storytelling
Wordpress plugin development from Scratch
Rebooting TEI Pointers
Exploiting Php With Php
WordPress Queries - the right way
Fixing Magento Core for Better Performance - Ivan Chepurnyi
Curso Symfony - Clase 3
New tags in html5
購物車程式架構簡介
Unit testing with zend framework PHPBenelux
Ad

Similar to SugarCon 2010 - Best Practices for Creating Custom Apps in Sugar (20)

PPTX
OSCON 2011 - Making Your PHP Application Easy to Customize
KEY
ModelAdmin in SilverStripe 2.3
PPT
Create Components in TomatoCMS
PDF
Alfredo-PUMEX
PDF
Alfredo-PUMEX
PDF
Alfredo-PUMEX
PDF
Alfredo-PUMEX
PPTX
Sugar U: Session 7: An Introduction to Sugar Development, Going Way Beyond St...
PDF
Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)
PPTX
Sugar U: Session 8: Configuring Sugar for Your Business Using Studio
DOCX
Interview Questions For Microsoft Dynamics CRM
PDF
Working With The Symfony Admin Generator
ODP
Silverstripe 2.4-highlights-gpmd
PPT
CiviCRM API v3
PPT
Vtiger: the case for analytic CRM
PPTX
June 10th: The SugarCRM Platform
PPTX
June 10th: The SugarCRM Platform
ODP
Codegnitorppt
PDF
Laravel for CRM Development A Detailed Guide.pdf
PPTX
Community Builder 2.0: Using a new way to build Web-Apps
OSCON 2011 - Making Your PHP Application Easy to Customize
ModelAdmin in SilverStripe 2.3
Create Components in TomatoCMS
Alfredo-PUMEX
Alfredo-PUMEX
Alfredo-PUMEX
Alfredo-PUMEX
Sugar U: Session 7: An Introduction to Sugar Development, Going Way Beyond St...
Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)
Sugar U: Session 8: Configuring Sugar for Your Business Using Studio
Interview Questions For Microsoft Dynamics CRM
Working With The Symfony Admin Generator
Silverstripe 2.4-highlights-gpmd
CiviCRM API v3
Vtiger: the case for analytic CRM
June 10th: The SugarCRM Platform
June 10th: The SugarCRM Platform
Codegnitorppt
Laravel for CRM Development A Detailed Guide.pdf
Community Builder 2.0: Using a new way to build Web-Apps
Ad

More from John Mertic (11)

PDF
The Virtual Git Summit - Subversion to Git - A Sugar Story
PPTX
PHPBenelux 2012 - Working successfully outside the cube
PPTX
LinuxCon Brazil 2011 - Hack your team, your Department, and Your Organization...
PPTX
Astricon 2011 - Connecting SugarCRM with your PBX
PPTX
OSCON 2011 - Building An Application On The SugarCRM Platform
PPTX
LinuxTag 2011 - Using SugarCRM when you aren't doing CRM Examples of SugarCRM...
PPTX
Making Software Management tools work for you - 2011 PHPBenelux Conference
PPT
SugarCON 2009 - Theme Development in Sugar 5.5
PPTX
Developing Easily Deployable PHP Applications ( OSCON 2010 )
PPTX
SugarCon 2010 - Sugar as a Business Application Framework
PPTX
2009 Ontario GNU Linux Fest - Build your business on SugarCRM
The Virtual Git Summit - Subversion to Git - A Sugar Story
PHPBenelux 2012 - Working successfully outside the cube
LinuxCon Brazil 2011 - Hack your team, your Department, and Your Organization...
Astricon 2011 - Connecting SugarCRM with your PBX
OSCON 2011 - Building An Application On The SugarCRM Platform
LinuxTag 2011 - Using SugarCRM when you aren't doing CRM Examples of SugarCRM...
Making Software Management tools work for you - 2011 PHPBenelux Conference
SugarCON 2009 - Theme Development in Sugar 5.5
Developing Easily Deployable PHP Applications ( OSCON 2010 )
SugarCon 2010 - Sugar as a Business Application Framework
2009 Ontario GNU Linux Fest - Build your business on SugarCRM

Recently uploaded (20)

PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
DOCX
The AUB Centre for AI in Media Proposal.docx
PPT
Teaching material agriculture food technology
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
KodekX | Application Modernization Development
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
cuic standard and advanced reporting.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
Understanding_Digital_Forensics_Presentation.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
MIND Revenue Release Quarter 2 2025 Press Release
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
The AUB Centre for AI in Media Proposal.docx
Teaching material agriculture food technology
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
KodekX | Application Modernization Development
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
cuic standard and advanced reporting.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Spectral efficient network and resource selection model in 5G networks
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Digital-Transformation-Roadmap-for-Companies.pptx
Programs and apps: productivity, graphics, security and other tools
Mobile App Security Testing_ A Comprehensive Guide.pdf

SugarCon 2010 - Best Practices for Creating Custom Apps in Sugar

  • 1. 4/14/10©2010 SugarCRM Inc. All rights reserved.1
  • 2. Best Practices for Creating Custom Apps in Sugar John MerticSugarCRM4/14/10©2010 SugarCRM Inc. All rights reserved.2
  • 3. The golden rules of customizationsUse Module Builder/Studio for customizations if possibleOtherwise, put your code inside the custom directory4/14/10©2010 SugarCRM Inc. All rights reserved.3
  • 4. Why do this?Module Builder/Studio changes are well supported and easier to manageCustomizations are separated from the shipped codeAllows you to manage your customizations via version control ( SVN, Git, etc )Files in here aren’t disturbed by any Sugar upgradesException – sometimes we will try to fix metadata templates on upgrades for new/removed fields. Makes your app “Upgrade Safe”4/14/10©2010 SugarCRM Inc. All rights reserved.4
  • 5. Exceptions to this…New modules need to be under modules/ directory.Bean class customizations to OOTB modules need to be on the original bean file.We’ll look at using logic hooks and other techniques to avoid this for many use cases.Will need to manually manage this during upgrades, so best to avoid.4/14/10©2010 SugarCRM Inc. All rights reserved.5
  • 6. Let’s see what we can do4/14/10©2010 SugarCRM Inc. All rights reserved.6
  • 7. MVC FrameworkMVC stands for Model View Controller4/14/10©2010 SugarCRM Inc. All rights reserved.7
  • 8. MVC Framework – The anatomy of a request4/14/10©2010 SugarCRM Inc. All rights reserved.8
  • 9. MVC Framework – SugarApplicationBootstraps the applicationLoads many of the default application settingsLanguageThemeSessionHandles User AuthenticationLoads the controller4/14/10©2010 SugarCRM Inc. All rights reserved.9
  • 10. MVC Framework - SugarControllerManages all the actions of a moduleContains logic for handling requests that don’t require a viewExample: Record savingMaps all other requests to the correct viewLogic for mapping an action of one name to a view of anotherCan detect if we should be using MVC or classic views4/14/10©2010 SugarCRM Inc. All rights reserved.10
  • 11. MVC Framework – SugarController API4/14/10©2010 SugarCRM Inc. All rights reserved.11
  • 12. MVC Framework – Controller Example4/14/10©2010 SugarCRM Inc. All rights reserved.12<?phpclass ExampleController extends SugarController{ public function action_hello() { echo "Hello World!"; } public function action_goodbye() { $this->view = 'goodbye'; }}
  • 13. MVC Framework – Controller-less mappingIf your module doesn’t need to have any controller logic, use action mapping insteads.Create file named action_view_map.php with the following contents:4/14/10©2010 SugarCRM Inc. All rights reserved.13<?php$action_view_map['goodbye'] = 'goodbye';
  • 14. MVC Framework - SugarViewContains the display logic for the actionUses a metadata backend for Edit, Detail, List, Popup viewsAnd Convert Lead in Sugar 6.0For other views, you write the code for the view and put it in modules/modulename/views/view.viewname.php4/14/10©2010 SugarCRM Inc. All rights reserved.14
  • 15. MVC Framework – SugarView API4/14/10©2010 SugarCRM Inc. All rights reserved.15
  • 16. MVC Framework – SugarView API4/14/10©2010 SugarCRM Inc. All rights reserved.16
  • 17. MVC Framework – View Example4/14/10©2010 SugarCRM Inc. All rights reserved.17<?phpclass ViewExample extends SugarView{ public function preDisplay() { if ( !is_admin($GLOBALS["current_user"]) )sugar_die("Not an Admin"); } public function display() { echo "Hello Admin!"; }}
  • 18. MVC Framework – ViewDetail Example4/14/10©2010 SugarCRM Inc. All rights reserved.18<?phprequire_once('include/MVC/View/views/view.detail.php');class ContactsViewDetail extends ViewDetail{ public function display() { $admin = new Administration(); $admin->retrieveSettings();if(isset($admin->settings['portal_on']) && $admin->settings['portal_on']) { $this->ss->assign("PORTAL_ENABLED", true); }parent::display(); }}
  • 19. 4/14/10©2010 SugarCRM Inc. All rights reserved.19Where do I put my customizations?Controllers/custom/modules/Modulename/controller.phpclass CustomModulenameController extends SugarControllerViews/custom/modules/Modulename/views/view.viewname.phpclass CustomModulenameViewViewname extends ModulenameViewViewnameIf that class doesn’t exist extend from ViewViewname or SugarView
  • 20. Metadata Layer4/14/10©2010 SugarCRM Inc. All rights reserved.20
  • 21. Kinds of metadataeditviewdefs.php / detailviewdefs.php / quickcreatedefs.phpWireless variants: wireless.editviewdefs.php, wireless.detailviewdefs.phpsubpaneldefs.phplistviewdefs.phpwireless.listviewdefs.phpsearchdefs.phpwireless.searchdefs.phpSearchFields.phppopupdefs.php4/14/10©2010 SugarCRM Inc. All rights reserved.21
  • 22. editviewdefs.php4/14/10©2010 SugarCRM Inc. All rights reserved.22<?php$viewdefs[$module_name]['EditView'] = array( 'templateMeta' => array( 'maxColumns' => '2', 'widths' => array(array('label' => '10', 'field' => '30'), array('label' => '10', 'field' => '30'), ), ), 'panels' =>array ( 'default' => array ( array ( 'name', 'assigned_user_name', ), array(array( 'name' => 'date_modified', 'customCode' => '{$fields.date_modified.value} {$APP.LBL_BY} {$fields.modified_by_name.value}', 'label' => 'LBL_DATE_MODIFIED',)), ), array( array ( 'description', ), ), ), );
  • 23. subpaneldefs.php4/14/10©2010 SugarCRM Inc. All rights reserved.23<?php$layout_defs[$module_name] = array( 'subpanel_setup' => array( 'contacts' => array( 'order' => 20, 'module' => 'Contacts', 'sort_by' => 'last_name, first_name', 'sort_order' => 'asc', 'subpanel_name' => 'default', 'get_subpanel_data' => 'contacts', 'title_key' => 'LBL_CONTACTS_SUBPANEL_TITLE', 'top_buttons' => array(array('widget_class' => 'SubPanelTopButtonQuickCreate'), array( 'widget_class'=>'SubPanelTopSelectButton', 'mode'=>'MultiSelect’ ), ), ), ),);
  • 24. searchdefs.php4/14/10©2010 SugarCRM Inc. All rights reserved.24<?php$searchdefs[$module_name] = array( 'templateMeta' => array( 'maxColumns' => '3', 'widths' => array('label' => '10', 'field' => '30'), ), 'layout' => array( 'basic_search' => array( 'name',array('name'=>'current_user_only', 'label'=>'LBL_CURRENT_USER_FILTER', 'type'=>'bool'), ), 'advanced_search' => array( 'name',array('name' => 'phone', 'label' =>'LBL_ANY_PHONE', 'type' => 'name'),array('name' => 'address_city', 'label' =>'LBL_CITY', 'type' => 'name'),array('name' => 'email', 'label' =>'LBL_ANY_EMAIL', 'type' => 'name'),array('name' => 'assigned_user_id', 'type' => 'enum', 'label' => 'LBL_ASSIGNED_TO', 'function' => array('name' => 'get_user_array', 'params' => array(false))), ), ),);
  • 25. SearchFields.php4/14/10©2010 SugarCRM Inc. All rights reserved.25<?php$searchFields[$module_name] = array ( 'name' => array( 'query_type'=>'default'), 'current_user_only'=> array('query_type'=>'default', 'db_field'=>array('assigned_user_id'),'my_items'=>true, 'vname' => 'LBL_CURRENT_USER_FILTER', 'type' => 'bool'), 'assigned_user_id'=> array('query_type'=>'default'),);
  • 26. popupdefs.php4/14/10©2010 SugarCRM Inc. All rights reserved.26<?phpglobal $mod_strings;$popupMeta = array( 'moduleMain' => 'Account', 'varName' => 'ACCOUNT', 'orderBy' => 'name', 'whereClauses' => array( 'name' => 'accounts.name', 'billing_address_city' => 'accounts.billing_address_city', 'phone_office' => 'accounts.phone_office'), 'searchInputs' => array('name', 'billing_address_city', 'phone_office'), 'create' => array( 'formBase' => 'AccountFormBase.php', 'formBaseClass' => 'AccountFormBase', 'getFormBodyParams' => array('','','AccountSave'), 'createButton' => $mod_strings['LNK_NEW_ACCOUNT’]), 'listviewdefs' => array( 'NAME' => array( 'width' => '40', 'label' => 'LBL_LIST_ACCOUNT_NAME', 'link' => true,'default' => true,), ), 'searchdefs' => array( 'name', array('name' => 'assigned_user_id', 'label'=>'LBL_ASSIGNED_TO', 'type' => 'enum', 'function' => array('name' => 'get_user_array', 'params' => array(false))), ),);
  • 27. Where do I put my customizations?Subpaneldefscustom/Extension/modules/Modulename/Ext/Layoutdefs/NameWhateverYouWant.phpNeed to run ‘Quick Repair and Rebuild’ after changes are madeEverything else/custom/modules/Modulename/metadataWatch for Studio blowing out your changes.4/14/10©2010 SugarCRM Inc. All rights reserved.27
  • 28. Logic Hooks4/14/10©2010 SugarCRM Inc. All rights reserved.28
  • 29. Logic Hook Types4/14/10©2010 SugarCRM Inc. All rights reserved.29
  • 30. Logic Hook Types (cont)4/14/10©2010 SugarCRM Inc. All rights reserved.30
  • 31. Logic Hook Types (new in 6.0)4/14/10©2010 SugarCRM Inc. All rights reserved.31
  • 32. logic_hooks.php4/14/10©2010 SugarCRM Inc. All rights reserved.32<?php$hook_version = 1; $hook_array = Array(); $hook_array['before_save'] = Array(); $hook_array['before_save'][] = Array(1, 'AccountHooks', 'custom/Accounts/AccountHooks.php','AccountHooks', 'getParentAccountIndustry'); Parameters for Logic Hook DefinitionParameter 1 - Sorting index used to sort the arrays of logic hook definitions before they are processed.Parameter 2 - A string value to identify the hookParameter 3 - Path to the PHP file to include which contains your logic hook codeParameter 4 - Name of the PHP class the logic hook method is inParameter 5 - Name of the PHP method to call
  • 33. AccountHooks.php4/14/10©2010 SugarCRM Inc. All rights reserved.33<?phpclass AccountHooks{ public function getParentAccountIndustry( SugarBean $bean, $event, $arguments ) { if ( empty($bean->industry) && !empty($bean->parent_id) ) { $parentAccountFocus = new Account(); $parentAccountFocus->retrieve($bean->parent_id); if ( !empty($parentAccountFocus->id) ) $bean->industry = $parentAccountFocus->industry; } } }
  • 34. Where do I put my customizations?Application Level Logic Hooks/custom/modules/Module Level Logic Hooks/custom/modules/Modulename/4/14/10©2010 SugarCRM Inc. All rights reserved.34
  • 35. Themes4/14/10©2010 SugarCRM Inc. All rights reserved.35
  • 36. Theme Directory Layoutcss/ - contains all css filesimages/ - contains all imagesjs/ - contains any js files.tpls/ - smarty templatesthemedef.php definition file.12/30/08©2009 SugarCRM Inc. All rights reserved.36
  • 37. Themes can inherit from other themesTheme Inheritance Model12/30/08©2009 SugarCRM Inc. All rights reserved.37
  • 38. Allow upgrade-safe modifications to themesAll themes can be modified by putting the replacement or overriding file in the custom/theme/<themename> directoryImage, HTML template file overrides are used as a replacement of the previous fileExample: an image custom/theme/<themename>/dog.gif would be used instead of theme/<themename>/dog.gif CSS and Javascript files are combined in order of inheritanceUses cssmin and jsmin to help reduce file sizeNo further code changes are required – changes are picked up automatically when themes cache is rebuilt.12/30/08©2009 SugarCRM Inc. All rights reserved.38
  • 39. Resources4/14/10©2010 SugarCRM Inc. All rights reserved.39http://developers.sugarcrm.comBuy my book!
  • 40. Thanks for coming!4/14/10©2010 SugarCRM Inc. All rights reserved.40