Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create add-campaign-support-custom-module.adoc #478

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 182 additions & 0 deletions content/blog/add-campaign-support-custom-module.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
---
title: How to Add Campaign/Target List Support for a Custom Module (contacts)
date: 2021-08-03T12:00:00+01:00
author: Paul Stevens
tags: ["development"]
hidden: true
---

---


== The Problem ==

Just creating a relationship between your custom module contacts and Target Lists does not allow you to use the campaign feature like you're used to with Leads, Targets and Contacts. In order to add campaign functionality to a custom contact module, you must do the following:


== Before You Start ==

* Create a *One to Many* relationship between your custom module and *“Activities”* module.
* Create a *One to Many* relationship between your custom module and *“Emails”* module.

{{% notice note %}}
In the code below 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.
{{% /notice %}}

=== 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.

.`custom/modules/{MODULE}/views/view.list.php`
[source,php]
-----
<?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`
[source,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`
[source,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`
[source,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

.`custom/extensions/modules/ProspectLists/Ext/Vardefs/custom.php`
[source,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:
.`modules/EmailMan/EmailMan.php`
[source,php]
-----
$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:

.`modules/EmailMan/EmailMan.php`
[source,php]
-----
case '{MODULE}':
$rel_name="{MODULE_EMAILS_REL_NAME}";
break;
-----

{{% notice note %}}
Don't forget to do a Repair and Rebuild!
{{% /notice %}}


_This blog post is a refurbished http://web.archive.org/web/20140825230331/http:/sugaruk.co.uk/blog/how-add-campaigntarget-list-support-custom-person-module-sugarcrm[article] from 2014_