Appendix A - Code Examples

Metadata

This is an example of setting up a function subpanel (see the Metadata chapter for more information).

In this example the cases module has a custom field incident_code_c which is used to track cases with the same root cause. We’ll add a subpanel to show all cases that have the same incident_code_c.

Initially we add to the subpanel_setup section of Cases by creating the following file in custom/Extension/modules/Cases/Ext/Layoutdefs/IncidentLayoutdefs.php

Example A.1: IncidentLayoutdefs.php
<?php
$layout_defs["Cases"]["subpanel_setup"]['incident_cases'] = array(
   'module' => 'Cases',
   'title_key' => 'LBL_INCIDENT_CASES',
   'subpanel_name' => 'default',
   'get_subpanel_data' => 'function:get_cases_by_incident',
   'function_parameters' =>
           array('import_function_file' => 'custom/modules/Cases/IncidentUtils.php',),
);

Next we create the file which will define our get_cases_by_incident function custom/modules/Cases/IncidentUtils.php.

Example A.2: IncidentUtils.php
<?php
 function get_cases_by_incident(){
         global $db;
         //Get the current bean
         $bean = $GLOBALS['app']->controller->bean;
         $incidentCode = $db->quote($bean->incident_code_c);
         //Create the SQL array
         $ret = array();
         $ret['select'] = ' SELECT id FROM cases ';
         $ret['from'] = ' FROM cases ';
         $ret['join'] = "";
         //Get all cases where the incident code matches but exclude the current case.
         $ret['where']="WHERE cases.deleted = 0 AND cases_cstm.incident_code_c = '{$incidentCode}' AND cases.id != '{$bean->id}'";
         return $ret;
}

Module Installer

The following is a basic example manifest file. See the Module Installer chapter.

Example A.3: Example manifest file
$manifest = array(
   'name' => 'Example manifest',
   'description' => 'A basic manifest example',
   'version' => '1.2.3',
   'author' => 'Jim Mackin',
   'readme' => 'This is a manifest example for the SuiteCRM for Developers book',
   'acceptable_sugar_flavors' => array('CE'),
   'acceptable_sugar_versions' => array(
       'exact_matches' => array('6.5.20',),
   ),
   'dependencies' => array(
     array(
       'id_name' => 'hello_world',
       'version' => '3.2.1'
     ),
   ),
   'icon' => 'ManifestExample.png',
   'is_uninstallable' => true,
   'published_date' => '2015-05-05',
   'type' => 'module',
   'remove_tables' => 'prompt',
 );
 $installdefs = array(
   'id' => 'suitecrmfordevelopers_example_manifest',
   'image_dir' => '/images/',
   'copy' => array(
     array(
       'from' => '/modules/ExampleModule',
       'to' => 'modules/ExampleModule',
     ),
   ),
   'dashlets' => array(
     array(
       'from' => '/modules/ExampleModule/Dashlets/',
       'name' => 'ExampleModuleDashlet'
     )
   ),
   'language' => array(
     array(
       'from' => 'application/language/en_us.examplemoduleadmin.php',
       'to_module' => 'application',
       'language' => 'en_us'
     ),
     array(
       'from' => '/modules/Accounts/language/en_us.examplemodule.php',
       'to_module' => 'Accounts',
       'language' => 'en_us'
     ),
     array(
       'from' => '/application/language/es_es.examplemoduleadmin.php',
       'to_module' => 'application',
       'language' => 'es_es'
     ),
     array(
       'from' => '/modules/Accounts/language/es_es.examplemodule.php',
       'to_module' => 'Accounts',
       'language' => 'es_es'
     ),
   ),
   'custom_fields' => array(
     array(
       'name' => 'example_field',
       'label' => 'Example Field',
       'type' => 'varchar',
       'max_size' =>  100,
       'module' => 'Accounts',
     ),
   ),
   'vardefs' => array(
     array(
       'from' => 'modules/Accounts/vardefs/examplemodule_vardefs.php',
       'to_module' => 'Accounts',
     ),
   ),
   'beans' => array(
     array(
       'module' => 'ExampleModule',
       'class' => 'ExampleModule',
       'path' => 'modules/ExampleModule/ExampleModule.php',
     ),
   ),
   'logic_hooks' => array(
     array(
       'module' => 'Accounts',
       'hook' => 'before_save',
       'order' => 100,
       'description'  => 'Example module before save hook',
       'file' => 'modules/ExampleModule/ExampleModuleHook.php',
       'class' => 'ExampleModuleLogicHooks',
       'function' => 'accounts_before_save',
     ),
   ),
   'administration' => array(
     array(
       'from' => 'modules/administration/examplemodule_admin.php',
     ),
   ),
 );
 $upgrade_manifest = array(
);

Content is available under GNU Free Documentation License 1.3 or later unless otherwise noted.