Skip to content

Commit

Permalink
[#47] Simplify evaluating required address components and re-arrange …
Browse files Browse the repository at this point in the history
…profile form
  • Loading branch information
jensschuppe committed May 2, 2022
1 parent 3656b41 commit 6779349
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 43 deletions.
33 changes: 14 additions & 19 deletions api/v3/TwingleDonation/Submit.php
Expand Up @@ -335,25 +335,20 @@ 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]);
// Remove address data when any address component that is configured as
// required is missing.
// See https://github.com/systopia/de.systopia.twingle/issues/47
foreach ($profile->getAttribute('required_address_components', []) as $required_address_component) {
if (empty($params[$required_address_component])) {
foreach ([
'street_address',
'postal_code',
'city',
'country',
] as $address_param) {
unset($params[$address_param]);
}
break;
}
}

Expand Down
8 changes: 5 additions & 3 deletions templates/CRM/Twingle/Form/Profile.hlp
Expand Up @@ -12,6 +12,7 @@
| written permission from the original author(s). |
+-------------------------------------------------------------*}

{crmScope extensionKey='de.systopia.twingle'}
{htxt id='id-location_type_id'}
{ts domain="de.systopia.twingle"}Select which location type to use for addresses for individuals, either when no organisation name is specified, or an organisation address can not be shared with the individual contact.{/ts}
{/htxt}
Expand Down Expand Up @@ -55,9 +56,9 @@
{/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>
<p>{ts}Select the address components that must be present to create or update an address for the contact.{/ts}</p>
<p>{ts}Depending on your XCM settings, the transferred address might replace an existing one.{/ts}</p>
<p>{ts}Since in some cases Twingle send the country of the user as the only address parameter, depending on your XCM configuration, not declaring other address components as required might lead to the current user address being overwritten with an address containing the country only.{/ts}</p>
{/htxt}

{htxt id='id-custom_field_mapping'}
Expand All @@ -74,3 +75,4 @@
<li><strong>ContributionRecur</strong> &ndash; Will be set on the recurring contribution and deriving single contributions</li>
</ul>{/ts}
{/htxt}
{/crmScope}
42 changes: 21 additions & 21 deletions templates/CRM/Twingle/Form/Profile.tpl
Expand Up @@ -113,6 +113,27 @@
<td class="content">{$form.location_type_id_organisation.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.financial_type_id.label}
Expand Down Expand Up @@ -290,27 +311,6 @@
<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

0 comments on commit 6779349

Please sign in to comment.