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

Allow configuring required address comonents #48

Merged
merged 8 commits into from May 2, 2022
14 changes: 14 additions & 0 deletions CRM/Twingle/Form/Profile.php
Expand Up @@ -416,6 +416,20 @@ public function buildQuickForm() {
array()
);

$this->add(
'select',
'required_address_components',
E::ts('Required address components'),
[
'street_address' => E::ts("Street"),
'postal_code' => E::ts("Postal Code"),
'city' => E::ts("City"),
'country' => E::ts("Country"),
],
FALSE, // is not required
['class' => 'crm-select2 huge', 'multiple' => 'multiple']
);

$this->add(
'textarea', // field type
'custom_field_mapping', // field name
Expand Down
9 changes: 8 additions & 1 deletion CRM/Twingle/Profile.php
Expand Up @@ -226,7 +226,8 @@ public static function allowedAttributes() {
'membership_type_id',
'membership_type_id_recur',
'membership_postprocess_call',
'newsletter_double_opt_in'
'newsletter_double_opt_in',
'required_address_components',
),
// Add payment methods.
array_keys(static::paymentInstruments()),
Expand Down Expand Up @@ -300,6 +301,12 @@ public static function createDefaultProfile($name = 'default') {
'membership_type_id' => NULL,
'membership_type_id_recur' => NULL,
'newsletter_double_opt_in' => NULL,
'required_address_components' => [
'street_address',
'postal_code',
'city',
'country',
],
)
// Add contribution status for all payment methods.
+ array_fill_keys(array_map(function($attribute) {
Expand Down
22 changes: 22 additions & 0 deletions api/v3/TwingleDonation/Submit.php
Expand Up @@ -335,6 +335,28 @@ function civicrm_api3_twingle_donation_Submit($params) {
}
}

// Make required address components configurable to prevent existing
// contact addresses from being overwritten with incomplete address
// information. See issue #47
$required_address_components =
$profile->getAttribute('required_address_components');
$unset_address_params = False;
foreach ($required_address_components as $req) {
if (empty($params[$req])) {
$unset_address_params = True;
}
}
if ($unset_address_params) {
foreach([
'street_address',
'postal_code',
'city',
'country',
] as $req) {
unset($params[$req]);
}
}

// Prepare parameter mapping for organisation.
if (!empty($params['user_company'])) {
$params['organization_name'] = $params['user_company'];
Expand Down
6 changes: 6 additions & 0 deletions templates/CRM/Twingle/Form/Profile.hlp
Expand Up @@ -54,6 +54,12 @@
</ul>{/ts}
{/htxt}

{htxt id='id-required_address_components'}
<p>{ts domain="de.systopia.twingle"}Select the address components that must be present to create a new address for the contact.{/ts}</p>
<p>{ts domain="de.systopia.twingle"}Depending on your XCM settings, the newly transferred address will replace the old one. This behavior may be intentional, as you always want to have the most current address.{/ts}</p>
<p>{ts domain="de.systopia.twingle"}<strong>ATTENTION:</strong> In some cases Twingle sends only the country of the user. If no other address components are selected in the required address components, the current user address will be overwritten with an address containing only the country, depending on the XCM settings.{/ts}</p>
{/htxt}

{htxt id='id-custom_field_mapping'}
{ts domain="de.systopia.twingle"}<p>Map Twingle custom fields to CiviCRM custom fields using the following format (each assignment in a separate line):</p>
<pre>twingle_field_1=custom_123<br />twingle_field_2=custom_789</pre>
Expand Down
21 changes: 21 additions & 0 deletions templates/CRM/Twingle/Form/Profile.tpl
Expand Up @@ -290,6 +290,27 @@
<td class="content">{$form.contribution_source.html}</td>
</tr>

<tr class="crm-section">
<td class="label">{$form.required_address_components.label}
<a
onclick='
CRM.help(
"{ts domain="de.systopia.twingle"}Required address components{/ts}",
{literal}{
"id": "id-required_address_components",
"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.required_address_components.html}</td>
</tr>

<tr class="crm-section">
<td class="label">
{$form.custom_field_mapping.label}
Expand Down