Make required address components configurable

The required address components can be selected in the corresponding profile.
This commit is contained in:
Marc Michalsky 2021-11-17 16:23:29 +01:00
parent 89638a172d
commit 9969c99f70
5 changed files with 63 additions and 9 deletions

View file

@ -416,6 +416,20 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
array() 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( $this->add(
'textarea', // field type 'textarea', // field type
'custom_field_mapping', // field name 'custom_field_mapping', // field name

View file

@ -226,7 +226,8 @@ class CRM_Twingle_Profile {
'membership_type_id', 'membership_type_id',
'membership_type_id_recur', 'membership_type_id_recur',
'membership_postprocess_call', 'membership_postprocess_call',
'newsletter_double_opt_in' 'newsletter_double_opt_in',
'required_address_components',
), ),
// Add payment methods. // Add payment methods.
array_keys(static::paymentInstruments()), array_keys(static::paymentInstruments()),
@ -300,6 +301,12 @@ class CRM_Twingle_Profile {
'membership_type_id' => NULL, 'membership_type_id' => NULL,
'membership_type_id_recur' => NULL, 'membership_type_id_recur' => NULL,
'newsletter_double_opt_in' => NULL, 'newsletter_double_opt_in' => NULL,
'required_address_components' => [
'street_address',
'postal_code',
'city',
'country',
],
) )
// Add contribution status for all payment methods. // Add contribution status for all payment methods.
+ array_fill_keys(array_map(function($attribute) { + array_fill_keys(array_map(function($attribute) {

View file

@ -335,14 +335,20 @@ function civicrm_api3_twingle_donation_Submit($params) {
} }
} }
// Do not creat a new address if user_country is the only address // Do not creat a new address if 'country' is the only address
// parameter. See issue #47 // component. See issue #47
if ( $required_address_components =
!array_key_exists('street_address', $params) && $profile->getAttribute('required_address_components');
!array_key_exists('postal_code', $params) && $unset_address_params = False;
!array_key_exists('city', $params) foreach ($required_address_components as $req) {
) { if (empty($params[$req])) {
unset($params['country']); $unset_address_params = True;
}
}
if ($unset_address_params) {
foreach($required_address_components as $req) {
unset($params[$req]);
}
} }
// Prepare parameter mapping for organisation. // Prepare parameter mapping for organisation.

View file

@ -54,6 +54,12 @@
</ul>{/ts} </ul>{/ts}
{/htxt} {/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'} {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> {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> <pre>twingle_field_1=custom_123<br />twingle_field_2=custom_789</pre>

View file

@ -290,6 +290,27 @@
<td class="content">{$form.contribution_source.html}</td> <td class="content">{$form.contribution_source.html}</td>
</tr> </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"> <tr class="crm-section">
<td class="label"> <td class="label">
{$form.custom_field_mapping.label} {$form.custom_field_mapping.label}