From 36a756e4dd599ed3613b7d575514903f97dd9271 Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Thu, 4 Jun 2020 14:21:06 +0200 Subject: [PATCH 1/2] [#28] Add parameter for preferred language and pass to XCM --- CRM/Twingle/Submission.php | 8 ++++++++ api/v3/TwingleDonation/Submit.php | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/CRM/Twingle/Submission.php b/CRM/Twingle/Submission.php index ddd239e..bf8efd0 100644 --- a/CRM/Twingle/Submission.php +++ b/CRM/Twingle/Submission.php @@ -177,6 +177,14 @@ class CRM_Twingle_Submission { } } + // Prepare values: language. + if (!empty($contact_data['preferred_language'])) { + $mapping = CRM_Core_I18n_PseudoConstant::longForShortMapping(); + // Override the default mapping for German. + $mapping['de'] = 'de_DE'; + $contact_data['preferred_language'] = $mapping[$contact_data['preferred_language']]; + } + // Pass to XCM. $contact_data['contact_type'] = $contact_type; $contact = civicrm_api3('Contact', 'getorcreate', $contact_data); diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index 5856996..de8fee4 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -224,6 +224,13 @@ function _civicrm_api3_twingle_donation_Submit_spec(&$params) { 'api.required' => 0, 'description' => E::ts('The company of the contact.'), ); + $params['user_extrafield'] = array( + 'name' => 'user_language', + 'title' => E::ts('Language'), + 'type' => CRM_Utils_Type::T_STRING, + 'api.required' => 0, + 'description' => E::ts('The preferred language of the contact. A 2-digit ISO-639-1 language code.'), + ); $params['user_extrafield'] = array( 'name' => 'user_extrafield', 'title' => E::ts('User extra field'), @@ -376,6 +383,7 @@ function civicrm_api3_twingle_donation_Submit($params) { 'user_birthdate' => 'birth_date', 'user_email' => 'email', 'user_telephone' => 'phone', + 'user_language' => 'preferred_language', 'user_title' => 'formal_title', 'debit_iban' => 'iban', ) as $contact_param => $contact_component) { From c81e10faaa91504b1acb04564c4fa7aa9cd53487 Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Mon, 2 May 2022 15:24:58 +0200 Subject: [PATCH 2/2] [#28] Add API parameter documentation and fix typo in API sepc --- README.md | 3 ++- api/v3/TwingleDonation/Submit.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dd5113d..848a792 100644 --- a/README.md +++ b/README.md @@ -102,10 +102,11 @@ The action accepts the following parameters: | `user_street` | String | The street address of the contact | | | | `user_postal_code` | String | The postal code of the contact | | | | `user_city` | String | The city of the contact | | | -| `user_country` | String | The country of the contact | [ISO 3166-1 Alpha-2 country codes](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) | | +| `user_country` | String | The country of the contact | A [ISO 3166-1 Alpha-2 country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) | | | `user_telephone` | String | The telephone number of the contact | | | | `user_company` | String | The company of the contact | | | | `user_extrafield` | String | Additional information of the contact | | | +| `user_language` | String | The preferred language of the contact. | A [ISO-639-1 2-digit language code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) | | | `campaign_id` | Integer | The CiviCRM ID of a campaign to assign the contribution | A valid CiviCRM Campaign ID. This overrides the campaign ID configured within the profile. | | You may also refer to diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index de8fee4..9a64f3e 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -224,7 +224,7 @@ function _civicrm_api3_twingle_donation_Submit_spec(&$params) { 'api.required' => 0, 'description' => E::ts('The company of the contact.'), ); - $params['user_extrafield'] = array( + $params['user_language'] = array( 'name' => 'user_language', 'title' => E::ts('Language'), 'type' => CRM_Utils_Type::T_STRING,