Merge remote-tracking branch 'MarcMichalsky/issue/47'

[#48] Allow configuring required address comonents
This commit is contained in:
Jens Schuppe 2022-05-02 14:31:35 +02:00
commit d95813d1ad
5 changed files with 68 additions and 1 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,6 +335,23 @@ function civicrm_api3_twingle_donation_Submit($params) {
} }
} }
// 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;
}
}
// Prepare parameter mapping for organisation. // Prepare parameter mapping for organisation.
if (!empty($params['user_company'])) { if (!empty($params['user_company'])) {
$params['organization_name'] = $params['user_company']; $params['organization_name'] = $params['user_company'];

View file

@ -12,6 +12,7 @@
| written permission from the original author(s). | | written permission from the original author(s). |
+-------------------------------------------------------------*} +-------------------------------------------------------------*}
{crmScope extensionKey='de.systopia.twingle'}
{htxt id='id-location_type_id'} {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} {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} {/htxt}
@ -54,6 +55,12 @@
</ul>{/ts} </ul>{/ts}
{/htxt} {/htxt}
{htxt id='id-required_address_components'}
<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'} {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>
@ -68,3 +75,4 @@
<li><strong>ContributionRecur</strong> &ndash; Will be set on the recurring contribution and deriving single contributions</li> <li><strong>ContributionRecur</strong> &ndash; Will be set on the recurring contribution and deriving single contributions</li>
</ul>{/ts} </ul>{/ts}
{/htxt} {/htxt}
{/crmScope}

View file

@ -113,6 +113,27 @@
<td class="content">{$form.location_type_id_organisation.html}</td> <td class="content">{$form.location_type_id_organisation.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.financial_type_id.label} {$form.financial_type_id.label}