Sugar Community Edition 6.1 Documentation
Sugar Developer Guide
Chapter 4 Customizing Sugar
• Studio - Edit Dropdowns, Custom Fields, Layouts and Labels
• Module Builder - Build new modules to expand the functionality of SugarCRM
• Module Loader - Add or remove Sugar modules, themes, and language packs
• Dropdown Editor - Add, delete, or change the dropdown lists in the application
• Rename Tabs - Change the label of the module tabs
• Configure Module Tabs and Subpanels - Choose which module tabs and sub-panels to display within the application
• Configure Shortcut Bar – Select which modules are available in the Shortcuts bar.
• Configure Grouped Modules - Create and edit groupings of tabsFor further information on how to use these tools, please refer to the Sugar Application Guide. This guide will go into more detail on how to use the Module Builder and the Module Loader, as well as how to extend the Sugar system at the code-level beyond what these tools provide.However, any changes you make using the developer tools provided on the Admin screen (Module Builder, Studio, etc.) are upgrade-safe. Also, any code changes you make in the custom/ directory are also upgrade-safe.When developing in Sugar, we suggest that you turn on the Developer Mode (Admin->System Settings->Advanced->Developer Mode) to get the system to ignore the cached metadata files. This is especially helpful when you are directly altering templates, metadata, or language files. When using Module Builder or Studio, the system will automatically refresh the file cache. Be sure to turn off Developer Mode when you have completed your customizations since this mode does degrade system performance.
• /custom/include/language/ (for $app_strings or $app_list_strings)
• /custom/Extension/modules/<MODULE_NAME>/Ext/Language/ (for $mod_strings only)If you added a $module_menu=array(); to the top of this file, you would effectively clear out any of the standard menu items. You could then replace them all with new definitions.If the custom file is in the /custom/Extension/application/Ext/Menus/ directory, then your menu changes will affect shortcut menus in every module.For{$modulename}.phpFirst, create the file AddTimeStamp.php with the following contents.Next register this custom function by creating the file logic_hooks.php with the following contents.Now add these two files to the Media Inquiries zip file you just saved. Create a directory called “SugarModules/custom/” in the zip file and add the two files there. Then modify the manifest.php in the zip file to include the following definition in the $install_defs[‘copy’] array.First you must “build” your module. This can be done by either deploying your module or clicking the Publish button. Module Builder will then generate a folder for your package in “custom/modulebuilder/builds/”. Inside that folder is where Sugar will have placed the bean files for your new module(s). In this case we want
“custom/modulebuilder/builds/MediaTracking/SugarModules/modules/jsche_mediarequest”The Module Loader not only installs custom modules but installs the latest patches, themes, language packs, and Sugar Dashlets. The $upgrade_manifest variable is used to upgrade the application.The following section outlines the parameters specified in the $manifest array contained in the manifest file (manifest.php). An example manifest file is included later for your reference.$manifest array elements provide the Module Loader with descriptive information about the extension.
o acceptable_sugar_flavors - Specifies which Sugar Editions the package can be installed on. Accepted values are any combination of: OS (valid prior to Sugar 5.0.0), CE (valid after Sugar 5.0.0), PRO, and ENT.
o acceptable_sugar_versions - This directive contains two arrays:
o author - Contains the author of the package, i.e. “SugarCRM Inc.”
o copy_files - An array detailing the source and destination of files that should be copied during installation of the package. See the example manifest file below for details.
o dependencies - A set of dependencies that must be satisfied to install the module. This contains two arrays:
o description - A description of the package. Displayed during installation.
Note: Apostrophes (') are not supported in your description and will cause a Module Loader error.
o icon - A path (within the package ZIP file) to an icon image that will be displayed during installation. Examples include: “./patch_directory/icon.gif” and “./patch_directory/images/theme.gif”
o is_uninstallable - Setting this directive to TRUE allows the Sugar administrator to uninstall the package. Setting this directive to FALSE disables the uninstall feature.
o name - The name of the package. Displayed during installation. Note: Apostrophes (') are not supported in your description and will cause a Module Loader error.
o published_date - The date the package was published. Displayed during installation.
o type - The package type. Accepted values are:
o langpack - Packages of type langpack will be automatically added to the “Language” dropdown on the Sugar Login screen. They are installed using the Upgrade Wizard.
o module - Packages of type module are installed using the Module Loader.
o patch - Packages of type patch are installed using the Upgrade Wizard.
o theme - Packages of type theme will be automatically added to the “Theme” dropdown on the Sugar Login screen. They are installed using the Upgrade Wizard.
o version - The version of the patch, i.e. “1.0” or “0.96-pre1” .The following section outlines the parameters specified in the $installdef array contained in the manifest file (manifest.php). An example manifest file is included later for your reference.$installdef array elements are used by the Module Loader to determine the actual installation steps that need to be taken to install the extension.
• id - A unique name for your module; for example, “Songs”
• copy - An array detailing files to be copied to the Sugar directory. A source path and destination path must be specified for each file or directory. See the example manifest file below for details.
• language - An array detailing individual language files for your module. The source path, destination file, and language pack name must be specified for each language file. See the example manifest file below for details.
• layoutdefs - An array detailing individual layoutdef files, which are used primarily for setting up subpanels in other modules. The source path and destination module must be specified for each layoutdef file. See the example manifest file below for details.
• layoutfields - An array detailing custom fields to be added to existing layouts. The fields will be added to the edit and detail views of target modules. See the example manifest file below for details.
• vardefs - An array detailing individual vardef files, which are used primarily for defining fields and non many-to-many relationships in other modules. The source path and destination module must be specified for each vardef file. See the example manifest file below for details.
• menu - An array detailing the menu file for your new module. A source path and destination module must be specified for each menu file. See the example manifest file below for details.
• beans - An array specifying the bean files for your new module. The following sub-directives must be specified for each bean:
• relationships - An array detailing relationship files, used to link your new modules to existing modules. A metadata path must be specified for each relationship. See the example manifest file below for details.
• custom_fields - An array detailing custom fields to be installed for your new module. The following sub-directives must be specified for each custom field:This array definition describes the release(s) leading to the "version" element defined in $manifest. In the sample manifest below it defines the Songs module versions 1.0 and 1.5 as preceding the current version 2.0.
To add additional function calls to the black list, add the function calls to the blackList array. The example below blocks the strlen() and strtolower() functions from being included in the package:
•
•
•
•
•
•
•
•
•
•
•
• The following sample manifest file defines the $manifest and $installdef array elements for a new module (Songs) which depends on two other modules: "Whale Pod" and "Maps". In addition to defining the $manifest and $installdef array elements, it also defines the $upgrade_manifest array.Custom Logic (or "Business Logic Hooks") allows you to add functionality to certain actions, such as before saving a bean, in an upgrade-safe manner. This is accomplished by defining hooks, which are placed in the custom/ directory, which will be called in the SugarBean in response to events at runtime. Because the code is located separate from the core SugarCRM code, it is upgrade-safe.See this SugarForge project for a complete example of a useful business hook.The code that declares your custom logic is located in: custom/modules/<CURRENT_MODULE>/logic_hooks.php. The format of the declaration follows.All logic hooks should define the $hook_version that should be used. Currently, the only supported $hook_version is 1.
o name: the name of the event that you are hooking your custom logic to
o array: an array containing the parameters needed to fire the hookThe hooks are processed in the order in which they are added to the array. The first dimension is simply the current action, for example before_save. The following hooks are available:
o Fired before a record is saved.
Note: With certain modules, like Cases and Bugs, the human-readable ID of the record (like the case_number field in the Case module), is not available within a before_save call. This is because this business logic has not been executed yet.
o Fired after a record is saved.
Note: With certain modules, like Cases and Bugs, the human-readable ID of the record (like the case_number field in the Case module), is not available within a before_save call. This is because this business logic simply has not been executed yet.
o $bean - $this bean passed in by reference.
o $event - The string for the current event (i.e. before_save)
o $arguments - An array of arguments that are specific to the event.The section above shows how to create a custom_logic_hook that runs the function updateDescription() from the class updateDescription (those do not have to be the same as they are in this example) in the PHP file updateDescription.php. Below is the actual script from that PHP file.You see that the $bean is fed into the function and allows access to all of the fields for the currently selected record. Any changes you make to the array will be reflected in the actual data. For example, in this script we are changing the description field. As shown above, there is
o In order to compare new values with previous values to see whether a change has happened, use $bean->fetched_row['<field>'] (old value) and $bean-><field> (new value) in the before_save logic hook.
o Make sure that the entire custom/ directory is writable by the web server, or else the logic hooks code will not work properly.By default, the metadata framework provides default implementations for Cancel, Delete, Duplicate, Edit, Find Duplicates, and Save buttons. However, you may wish to use some of the default buttons or add additional buttons. Here is an example:
Here we are adding a custom button with the label defined in the Smarty variable {$APP.LBL_QUOTE_TO_OPPORTUNITY_LABEL}. The EDIT, DUPLICATE and DELETE buttons are rendered and then the snippet of code in this 'customCode' block is added.
Note: You do not have to necessarily create a view.edit.php file, but usually at this point of customization, you will want to add variables to your customized template that are not assigned by the generic EditView handling from the MVC framework. See the next example, Overriding the View, for more information about sub-classing the EditView and assigning Smarty variables to the resulting templates.Here the $JSON_CONFIG_JAVASCRIPT Smarty variable was the result of a complex operation and not available via the vardefs.php file (i.e. there is no JSON_CONFIG_JAVASCRIPT declaration in the vardefs.php file).
4) Create a directory include/SugarFields/Fields/YouTube. The name of the directory (YouTube) corresponds to the name of the field type you are creating.
5) In include/SugarFields/Fields/YouTube directory, create the file DetailView.tpl. For the DetailView we will use the "embed" tag to display the video. In order to do this, you need to add the following to the template file:Notes on structure of config - replace the default parameters if they are different for the page.
o method: Unless you make a new method on the JSON server, keep this as query.
o populate_list: This defines the id's of the fields to be populated after a selection is made.
QuickSearch will map the first item of field_list to the first item of populate_list. ie. field_list[0] = populate_list[0], field_list[1] = populate_list[1].... until the end of populate list.
o limit: reduce from 30 if query is large hit, but never less than 12.
o conditions: options are like_custom, contains, or default of starts with
if using 'like_custom' also define 'begin'/'end' for strings to prepend or append to the user input
o disable: set this to true to disable SQS (optional, useful for disabling SQS on parent types in calls for example)
o post_onblur_function: this is an optional function to be called after the user has made a selection. It will be passed in an array with the items in field_list as keys and their corresponding values for the selection as values.
4. Assign your config array to sqs_objects (important!)
6. Add id tags and class name to the input box. Note that the input box must have class="sqsEnabled"!Having trouble? Take a look at the file module/Contacts/BusinessCard.php.Sugar Enterprise and Professional editions now include a Downloads tab that appears on the User Preferences page. This tab lists links to download Sugar Plug-ins for Microsoft Office. If you do not want to display the Downloads tab to administrators and users, you need to add a configuration parameter named disable_download_tab to the config_override.php file with the value set to true, as shown below.
$sugar_config['disable_download_tab'] = true;NOTE: It is important to separate your JavaScript into a separate JavaScript file. This is because Sugar Dashlets are dynamically added to a page through AJAX. The HTML included into JavaScript is not evaluated when dynamically included.Creating a custom chart dashlet is very similar to how we created the MyAccountsDashlet above. The main difference is that you will need to override the display() method in your class to build the chart, using the SugarChart library included with SugarCRM. Below is an example display() method as used in the Outcome by Month dashlet.db_convert('opportunities.date_closed','date_format',array("'%Y-%m'"),array("'YYYY-MM'"))." as m, ".
o acceptable_sugar_flavors Contains which Sugar Editions the package can be installed on. Accepted values are any combination of: CE, PRO, and ENT.
o acceptable_sugar_versions This directive contains two arrays:
o author Contains the author of the package; for example, “SugarCRM Inc.”
o copy_files An array detailing the source and destination of files that should be copied during installation of the package. See the example manifest file below for details.
o description A description of the package. Displayed during installation.
o icon A path (within the package ZIP file) to an icon image that will be displayed during installation. Examples include “./patch_directory/icon.gif” and “./patch_directory/images/theme.gif”
o is_uninstallable Setting this directive to TRUE allows the Sugar administrator to uninstall the package. Setting this directive to FALSE disables the uninstall feature.
o name The name of the package. Displayed during installation.
o published_date The date the package was published. Displayed during installation.
o type The package type. This should be set to “theme”
o version The version of the patch, i.e. “1.0” or “0.96-pre1”Note: You can also set the default language in the config.php. This value is used if a user does not specify a language while logging into the application.Note: Some language files that ship with Sugar are not named “en_us.lang.php” but are “.html” or “.tpl” files. These files are used for the inline help system. A complete language pack will include the translated versions of these files as well.Note: In the include/language/<new>.lang.php file, you will see that there are two global arrays defined. The $app_list_strings array is actually an array of arrays. The key values in this array must not be changed. There are comments and examples in the code that should keep you on track.Note: Be careful to choose a language pack that is up to date and is working.
o Optionally, include localized Help files for each view in each module. For example, for the Portugese (Brazilian) language pack, you would include pt_br.help.index.html (for List View), pt_br.help.DetailView.html (for Detail View), and pt_br.help.EditView.html (for Edit View).
ViewSugarpdf (include/MVC/View/views/view.sugarpdf.php)module=<mymodule>&action=sugarpdf&sugarpdf=<XXX>Sugarpdf (include/Sugarpdf/Sugarpdf.php)
• Header - This method override the regular Header() method to enable the custom image directory in addition to the OOB image directory.
• SetFont - This method override the regular SetFont() method to enable the custom font directory in addition to the OOB font directory.
• Cell - Handle HTML entity decode.
• getNumLines - This method is a fix for a better handling of the count. It handle the line break between words.
• predisplay - preprocessing before the display method is called. Is intended to setup general PDF document properties like margin, footer, header, etc.
• display - performs the actual PDF content generation. This is where the logic to display output to the PDF should be placed.
•
• writeCellTable – Method to print a table using the Cell print method of TCPDF
• writeHTMLTable - Method to print a table using the writeHTML print method of TCPDFThis file is included by Sugarpdf.php. This php file is a utils file. It contains many functions that can be used to generate PDFs.The font list build by the font manager with the listFontFiles() or getSelectFontList() is saved in a cached php file cache/Sugarpdf/cachedFontList.php to prevent to parse the fonts folder every time (if the cached file don't already exist). This file is automatically cleared when the delete() or add() methods are used.include/Sugarpdf/sugarpdf_default.php is used to store the default value of the PDF settings (system and user).You can overwrite any default value using custom/include/Sugarpdf/sugarpdf_default.php.For example if you want to set the default right margin to 25 pdf units, create or modify the file custom/include/Sugarpdf/sugarpdf_default.php with this content:
1. The font manager parses this directory for available custom font files in addition to the OOB directory.All the uploaded logos from PDF settings are copied to this location.This file is included after the OOB sugarpdf_default.php file. It can be used to overwrite any default value for the PDF settings.These files are used to override a sugarpdf.XXX.php class for a specific module or for the whole application.
1. Add the file custom/modules/<myModule>/sugarpdf/sugarpdf.<mySugarpdf>.php
a) require include/Sugarpdf/Sugarpdf.phpYou can choose to create a PDF from a Smarty template. You will have to assign variables to the Smarty template, generate the HTML with Smarty and pass it to TCPDF using the WriteHTML() method. The SugarpdfSmarty class is an helper class which support part of these steps.Warning : HTML and CSS support in writeHTML() is limited. For more details, read the TCPDF documentation
• Add custom/modules/Contacts/sugarpdf/sugarpdf.test.php with this content :
• Add custom/modules/Contacts/tpls/test.tpl with this content :
• Generate the PDF file using this URL : module=Contacts&action=sugarpdf&sugarpdf=test
• Create the directory custom/include/tcpdf/fonts if it is not created
• Copy these files into the directory custom/include/tcpdf/fonts
• Create the directory custom/include/tcpdf/fonts if it is not created
• Copy all the generated files (.php AND .z and .ctg.z if generated) into the directory custom/include/tcpdf/fontsmakefont.php and the utilities use in the TCPDF Fonts webpage can be found in the TCPDF package in fonts/utils. You can download the TCPDF package [here].
• Create custom/modules/Configurator/metadata/SugarpdfSettingsdefs.phpNote : You can view all the available settings in modules/Configurator/metadata/SugarpdfSettingsdefs.php (commented and not commented).
1. Add the following parameter to config_override.php:While you can enable these settings, support from SugarCRM for these features is no longer available. To re-enable these settings, you will need to add a configuration parameter to the config_override.php file with the value set to true.
For example, to enable the POP3 protocol, the config_override.php file would have the following entry set:
Copyright 2004-2010 SugarCRM Inc.
Community Edition License
User Contributed Comments
No user comments found.Add a Comment








