Merge branch 'issue/36'
[#36] Use CiviCRM's double opt-in feature for newsletter subscription
This commit is contained in:
commit
72a3515e8a
7 changed files with 120 additions and 24 deletions
|
@ -327,6 +327,14 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
);
|
||||
}
|
||||
|
||||
$this->add(
|
||||
'checkbox', // field type
|
||||
'newsletter_double_opt_in', // field name
|
||||
E::ts('Use Double-Opt-In for newsletter'), // field label
|
||||
FALSE, // is not required
|
||||
array()
|
||||
);
|
||||
|
||||
$this->add(
|
||||
'select', // field type
|
||||
'newsletter_groups', // field name
|
||||
|
@ -549,6 +557,9 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
}
|
||||
$this->profile->setName($values['name']);
|
||||
foreach ($this->profile->getData() as $element_name => $value) {
|
||||
if ($element_name == 'newsletter_double_opt_in') {
|
||||
$values[$element_name] = (int) isset($values[$element_name]);
|
||||
}
|
||||
if (isset($values[$element_name])) {
|
||||
$this->profile->setAttribute($element_name, $values[$element_name]);
|
||||
}
|
||||
|
@ -798,6 +809,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
* @return array
|
||||
*
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
*
|
||||
*/
|
||||
public static function getNewsletterGroups() {
|
||||
if (!isset(static::$_newsletterGroups)) {
|
||||
|
|
|
@ -221,6 +221,7 @@ class CRM_Twingle_Profile {
|
|||
'membership_type_id',
|
||||
'membership_type_id_recur',
|
||||
'membership_postprocess_call',
|
||||
'newsletter_double_opt_in'
|
||||
),
|
||||
// Add payment methods.
|
||||
array_keys(static::paymentInstruments()),
|
||||
|
@ -293,6 +294,7 @@ class CRM_Twingle_Profile {
|
|||
'custom_field_mapping' => NULL,
|
||||
'membership_type_id' => NULL,
|
||||
'membership_type_id_recur' => NULL,
|
||||
'newsletter_double_opt_in' => NULL,
|
||||
)
|
||||
// Add contribution status for all payment methods.
|
||||
+ array_fill_keys(array_map(function($attribute) {
|
||||
|
|
35
README.md
35
README.md
|
@ -43,23 +43,24 @@ The *default* profile is used whenever the plugin cannot match the Twingle
|
|||
project ID from any other profile. Therefore the default profile will be used
|
||||
for all newly created Twingle projects.
|
||||
|
||||
| Label | Description |
|
||||
|---------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| Profile name | Internal name, used inside the extension. |
|
||||
| Project IDs | Twingle project IDs. Separate multiple IDs with commas. |
|
||||
| Location type | Specify how the address data sent by the form should be categorised in CiviCRM. The list is based on your CiviCRM configuration. |
|
||||
| Location type for organisations | Specify how the address data sent by the form should be categorised in CiviCRM for organisational donations. The list is based on your CiviCRM configuration. |
|
||||
| Financial type | Specify which financial type incoming one-time donations should be recorded with in CiviCRM. The list is based on your CiviCRM configuration. |
|
||||
| Financial type (recurring) | Specify which financial type incoming recurring donations should be recorded with in CiviCRM. The list is based on your CiviCRM configuration. |
|
||||
| CiviSEPA creditor | When enabled to integrate with CiviSEPA, specify the CiviSEPA creditor to use. |
|
||||
| Gender options | Specify which CiviCRM gender option the incoming Twingle gender value should be mapped to. The list is based on your CiviCRM configuration. |
|
||||
| Record *Payment method* as | Specifiy the payment methods mapping for incoming donations for each Twingle payment method. |
|
||||
| Sign up for groups | Whenever the donor checked the newsletter/postal mailing/donation receipt checkbox on the Twingle form, the contact will be added to the groups listed here. |
|
||||
| Assign donation to campaign | The donation will be assigned to the selected campaign. If a campaign ID is being submitted using the `campaign_id` parameter, this setting will be overridden with the submitted value. |
|
||||
| Create membership of type | A membership of the selected type will be created for the Individual contact for incoming one-time donations. If no membership type is selected, no membership will be created. |
|
||||
| Create membership of type (recurring) | A membership of the selected type will be created for the Individual contact for incoming recurring donations. If no membership type is selected, no membership will be created. |
|
||||
| Contribution source | The configured value will be set as the "Source" field for the contribution. |
|
||||
| Custom field mapping | Additional field values may be set to CiviCRM custom fields using a mapping. See the option's help text for the exact format. |
|
||||
| Label | Description |
|
||||
|---------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| Profile name | Internal name, used inside the extension. |
|
||||
| Project IDs | Twingle project IDs. Separate multiple IDs with commas. |
|
||||
| Location type | Specify how the address data sent by the form should be categorised in CiviCRM. The list is based on your CiviCRM configuration. |
|
||||
| Location type for organisations | Specify how the address data sent by the form should be categorised in CiviCRM for organisational donations. The list is based on your CiviCRM configuration. |
|
||||
| Financial type | Specify which financial type incoming one-time donations should be recorded with in CiviCRM. The list is based on your CiviCRM configuration. |
|
||||
| Financial type (recurring) | Specify which financial type incoming recurring donations should be recorded with in CiviCRM. The list is based on your CiviCRM configuration. |
|
||||
| CiviSEPA creditor | When enabled to integrate with CiviSEPA, specify the CiviSEPA creditor to use. |
|
||||
| Gender options | Specify which CiviCRM gender option the incoming Twingle gender value should be mapped to. The list is based on your CiviCRM configuration. |
|
||||
| Record *Payment method* as | Specifiy the payment methods mapping for incoming donations for each Twingle payment method. |
|
||||
| Double Opt-In | Let CiviCRM handle the double opt-in. Group memberships for newsletter mailing lists stay pending until the subscription gets confirmed. Note that this only works for public mailing lists. Any non-public mailing list will be ignored. Do not forget to disable Twingle's double opt-in option in the Twingle Manager. |
|
||||
| Sign up for groups | Whenever the donor checked the newsletter/postal mailing/donation receipt checkbox on the Twingle form, the contact will be added to the groups listed here. |
|
||||
| Assign donation to campaign | The donation will be assigned to the selected campaign. If a campaign ID is being submitted using the `campaign_id` parameter, this setting will be overridden with the submitted value. |
|
||||
| Create membership of type | A membership of the selected type will be created for the Individual contact for incoming one-time donations. If no membership type is selected, no membership will be created. |
|
||||
| Create membership of type (recurring) | A membership of the selected type will be created for the Individual contact for incoming recurring donations. If no membership type is selected, no membership will be created. |
|
||||
| Contribution source | The configured value will be set as the "Source" field for the contribution. |
|
||||
| Custom field mapping | Additional field values may be set to CiviCRM custom fields using a mapping. See the option's help text for the exact format. |
|
||||
|
||||
|
||||
## API documentation
|
||||
|
|
|
@ -484,13 +484,63 @@ function civicrm_api3_twingle_donation_Submit($params) {
|
|||
$result_values['organization'] = $organisation_id;
|
||||
}
|
||||
|
||||
// If requested, add contact to newsletter groups defined in the profile.
|
||||
if (!empty($params['newsletter']) && !empty($groups = $profile->getAttribute('newsletter_groups'))) {
|
||||
// If usage of double opt-in is selected, use MailingEventSubscribe.create
|
||||
// to add contact to newsletter groups defined in the profile
|
||||
$result_values['newsletter']['newsletter_double_opt_in'] = ($profile->getAttribute('newsletter_double_opt_in')) ? 'true' : 'false';
|
||||
if (
|
||||
$profile->getAttribute('newsletter_double_opt_in') &&
|
||||
!empty($params['newsletter']) &&
|
||||
!empty($groups = $profile->getAttribute('newsletter_groups'))
|
||||
) {
|
||||
$group_memberships = array_column(
|
||||
civicrm_api3(
|
||||
'GroupContact',
|
||||
'get',
|
||||
array(
|
||||
'sequential' => 1,
|
||||
'contact_id' => $contact_id,
|
||||
)
|
||||
)['values'],
|
||||
'group_id'
|
||||
);
|
||||
foreach ($groups as $group_id) {
|
||||
civicrm_api3('GroupContact', 'create', array(
|
||||
'group_id' => $group_id,
|
||||
'contact_id' => $contact_id,
|
||||
));
|
||||
$is_public_group = civicrm_api3(
|
||||
'Group',
|
||||
'getsingle',
|
||||
array(
|
||||
'id' => (int) $group_id,
|
||||
)
|
||||
)['visibility'] == 'Public Pages';
|
||||
if (!in_array($group_id, $group_memberships) && $is_public_group) {
|
||||
$result_values['newsletter'][][$group_id] = civicrm_api3(
|
||||
'MailingEventSubscribe',
|
||||
'create',
|
||||
array(
|
||||
'email' => $params['user_email'],
|
||||
'group_id' => (int) $group_id,
|
||||
'contact_id' => $contact_id,
|
||||
)
|
||||
);
|
||||
}
|
||||
elseif ($is_public_group) {
|
||||
$result_values['newsletter'][] = $group_id;
|
||||
}
|
||||
}
|
||||
// If requested, add contact to newsletter groups defined in the profile.
|
||||
}
|
||||
elseif (
|
||||
!empty($params['newsletter'])
|
||||
&& !empty($groups = $profile->getAttribute('newsletter_groups'))
|
||||
) {
|
||||
foreach ($groups as $group_id) {
|
||||
civicrm_api3(
|
||||
'GroupContact',
|
||||
'create',
|
||||
array(
|
||||
'group_id' => $group_id,
|
||||
'contact_id' => $contact_id,
|
||||
)
|
||||
);
|
||||
|
||||
$result_values['newsletter'][] = $group_id;
|
||||
}
|
||||
|
|
|
@ -306,3 +306,7 @@ msgstr "Profil %1 zurücksetzen"
|
|||
#: templates/CRM/Twingle/Page/Profiles.tpl
|
||||
msgid "Delete profile %1"
|
||||
msgstr "Profil % 1 löschen"
|
||||
|
||||
#: templates/CRM/Twingle/Page/Profiles.tpl
|
||||
msgid "Use Double-Opt-In for newsletter"
|
||||
msgstr "Nutze Double-Opt-In für Newsletter"
|
||||
|
|
|
@ -38,6 +38,11 @@
|
|||
{ts domain="de.systopia.twingle"}Select which financial type to use for recurring contributions.{/ts}
|
||||
{/htxt}
|
||||
|
||||
{htxt id='id-newsletter-double-opt-in'}
|
||||
<p>{ts domain="de.systopia.twingle"}Select whether to use CiviCRM's Double-Opt-In feature for subscribing to mailing lists. Note that this only works for public mailing lists. Any non-public mailing list selected above will be ignored when this setting is enabled.{/ts}</p>
|
||||
<p>{ts domain="de.systopia.twingle"}Also, do not forget to disable Twingle's own Double Opt-In option in the Twingle Manager to avoid subscribers receiving multiple confirmation e-mails. Only one or the other option should be enabled.{/ts}</p>
|
||||
{/htxt}
|
||||
|
||||
{htxt id='id-membership-postprocessing-call'}
|
||||
{ts domain="de.systopia.twingle"}Some organisations have specific conventions on how a membership should be created. Since the Twingle-API can only create a "bare bone" membership object, you can enter a API Call (as 'Entity.Action') to adjust any newly created membership to your organisation's needs.{/ts}
|
||||
{ts domain="de.systopia.twingle"}The API call would receive the following parameters:<ul>
|
||||
|
|
|
@ -213,6 +213,28 @@
|
|||
<td class="content">{$form.newsletter_groups.html}</td>
|
||||
</tr>
|
||||
|
||||
<tr class="crm-section">
|
||||
<td class="label">
|
||||
{$form.newsletter_double_opt_in.label}
|
||||
<a
|
||||
onclick='
|
||||
CRM.help(
|
||||
"{ts domain="de.systopia.twingle"}Newsletter Double Opt-In{/ts}",
|
||||
{literal}{
|
||||
"id": "id-newsletter-double-opt-in",
|
||||
"file": "CRM\/Twingle\/Form\/Profile"
|
||||
}{/literal}
|
||||
);
|
||||
return false;
|
||||
'
|
||||
href="#"
|
||||
title="{ts domain="de.systopia.twingle"}Help{/ts}"
|
||||
class="helpicon"
|
||||
></a>
|
||||
</td>
|
||||
<td class="content">{$form.newsletter_double_opt_in.html}</td>
|
||||
</tr>
|
||||
|
||||
<tr class="crm-section">
|
||||
<td class="label">{$form.postinfo_groups.label}</td>
|
||||
<td class="content">{$form.postinfo_groups.html}</td>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue