How to Add Campaign/Target List Support for a Custom Module (contacts)
Adapted from: http://web.archive.org/web/20140825230331/http:/sugaruk.co.uk/blog/how-add-campaigntarget-list-support-custom-person-module-sugarcrm
Before you start:
-
Create One to Many relationship between your custom module and âActivitiesâ module
-
Create a One to Many relationship between your custom module and âEmailsâ module
In the code replace{module} with the name of your custom module. When you navigate to custom/modules/{module} the module name will be the name of the folder.
Step 1:
Add a custom list view for your custom module (custom/modules/{MODULE}/views/view.list.php)
You may have to create the files and directories.
<?php
require_once(âinclude/MVC/View/views/view.list.phpâ);
class {MODULE}ViewList extends ViewList
{
public function preDisplay()
{
parent::preDisplay();
$this->lv->targetList = true;
}
}
?>
Step 2:
Create extended vardef for prospect list â custom module relationship (custom/extension/modules/{MODULE}Ext/Vardefs/prospect_list_{MODULE}.php
<?php
$dictionary["{MODULE}"][ârelationshipsâ][âprospect_list_{MODULE}â] = array (
âlhs_moduleâ => âProspectListsâ,
âlhs_tableâ => âprospect_listsâ,
âlhs_keyâ => âidâ,
ârhs_moduleâ => â{MODULE}â,
ârhs_tableâ => â{MODULE_TABLE}â,
ârhs_keyâ => âidâ,
ârelationship_typeâ => âmany-to-manyâ,
âjoin_tableâ => âprospect_lists_prospectsâ,
âjoin_key_lhsâ => âprospect_list_idâ,
âjoin_key_rhsâ => ârelated_idâ,
ârelationship_role_columnâ => ârelated_typeâ,
ârelationship_role_column_valueâ => â{MODULE}â
);
$dictionary["{MODULE}"][âfieldsâ][âprospect_listsâ] = array (
ânameâ => âprospect_listsâ,
âtypeâ => âlinkâ,
ârelationshipâ => âprospect_list_{MODULE}â,
âsourceâ => ânon-dbâ
);
?>
Step 3:
Create a subpanel definition to show the prospect list subpanel on your custom module (custom/extension/modules/{MODULE}/Ext/Layoutdefs/ProspectListSubpanel.php)
<?php
$layout_defs["{MODULE}"][âsubpanel_setupâ][âprospect_listsâ] = array (
âorderâ => 10,
âsort_byâ => ânameâ,
âsort_orderâ => âascâ,
âmoduleâ => âProspectListsâ,
âsubpanel_nameâ => âdefaultâ,
âget_subpanel_dataâ => âprospect_listsâ,
âtitle_keyâ => âLBL_PROSPECT_LISTS_SUBPANEL_TITLEâ,
âtop_buttonsâ => array(
array(âwidget_classâ => âSubPanelTopButtonQuickCreateâ),
array(âwidget_classâ=>âSubPanelTopSelectButtonâ,âmodeâ=>âMultiSelectâ),
),
);
?>
Step 4:
Create a subpanel def for your custom module on the prospect list detailview(custom/extension/modules/ProspectLists/Ext/Layoutdefs/prospect_lists_{MODULE}.php
<?php
$layout_defs[âProspectListsâ][âsubpanel_setupâ]["{MODULE}"] = array ( //module name in lowercase
âorderâ => 10,
âsort_byâ => ânameâ,
âsort_orderâ => âascâ,
âmoduleâ => â{MODULE}â,
âsubpanel_nameâ => âForProspectListsâ,
âget_subpanel_dataâ => â{MODULE}â,//lowercase!!
âtitle_keyâ => âLBL_{MODULE}_SUBPANEL_TITLEâ,
âtop_buttonsâ => array(
array(âwidget_classâ => âSubPanelTopButtonQuickCreateâ),
array(âwidget_classâ=>âSubPanelTopSelectButtonâ,âmodeâ=>âMultiSelectâ),
),
);
?>
Step 5:
Create a vardef relationship field extension in custom/extensions/modules/ProspectLists/Ext/Vardefs/custom.php
<?php
$dictionary[âProspectListâ][âfieldsâ][â{MODULE}â] =array ( //module name in lowercase
ânameâ => â{MODULE}â,//lowercase!!
âtypeâ => âlinkâ,
ârelationshipâ => âprospect_list_{MODULE}â,
âsourceâ=>ânon-dbâ,
);
?>
Step 6:
Create subpanel metadata â Copy modules/{MODULE}/metadata/subpanels/default.php then rename and copy to: custom/modules/{MODULE}/metadata/subpanels/ForProspectLists.php
Step 7:
Edit modules/EmailMan/EmailMan.php around line 665 add:
$this->ref_email->load_relationship(â{MODULE_EMAILS_REL_NAMEâ);
You must have a relationship between your custom module and the emails module. You can find the name of the of relationship by looking in custom/Extension/modules/Emails/Ext/Vardefs/{MODULE}_activities_emails.php at the ânameâ property.
Around Line 689 Add:
case â{MODULE}â:
$rel_name="{MODULE_EMAILS_REL_NAME}";
break;
Donât Forget to do a Repair and Rebuild