From 6779349505ba35a54fa5a69948c40d50b6d68dc3 Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Mon, 2 May 2022 14:30:35 +0200 Subject: [PATCH] [#47] Simplify evaluating required address components and re-arrange profile form --- api/v3/TwingleDonation/Submit.php | 33 +++++++++----------- templates/CRM/Twingle/Form/Profile.hlp | 8 +++-- templates/CRM/Twingle/Form/Profile.tpl | 42 +++++++++++++------------- 3 files changed, 40 insertions(+), 43 deletions(-) diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index f773054..4025f97 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -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; } } diff --git a/templates/CRM/Twingle/Form/Profile.hlp b/templates/CRM/Twingle/Form/Profile.hlp index b4c6ff9..e3841d7 100644 --- a/templates/CRM/Twingle/Form/Profile.hlp +++ b/templates/CRM/Twingle/Form/Profile.hlp @@ -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} @@ -55,9 +56,9 @@ {/htxt} {htxt id='id-required_address_components'} -

{ts domain="de.systopia.twingle"}Select the address components that must be present to create a new address for the contact.{/ts}

-

{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}

-

{ts domain="de.systopia.twingle"}ATTENTION: 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}

+

{ts}Select the address components that must be present to create or update an address for the contact.{/ts}

+

{ts}Depending on your XCM settings, the transferred address might replace an existing one.{/ts}

+

{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}

{/htxt} {htxt id='id-custom_field_mapping'} @@ -74,3 +75,4 @@
  • ContributionRecur – Will be set on the recurring contribution and deriving single contributions
  • {/ts} {/htxt} +{/crmScope} \ No newline at end of file diff --git a/templates/CRM/Twingle/Form/Profile.tpl b/templates/CRM/Twingle/Form/Profile.tpl index 49a0097..00794ef 100644 --- a/templates/CRM/Twingle/Form/Profile.tpl +++ b/templates/CRM/Twingle/Form/Profile.tpl @@ -113,6 +113,27 @@ {$form.location_type_id_organisation.html} + + {$form.required_address_components.label} + + + {$form.required_address_components.html} + + {$form.financial_type_id.label} @@ -290,27 +311,6 @@ {$form.contribution_source.html} - - {$form.required_address_components.label} - - - {$form.required_address_components.html} - - {$form.custom_field_mapping.label}