From a6b3d675f4044f404cd47ea8fa3ef7896e333f37 Mon Sep 17 00:00:00 2001 From: Jaap Jansma Date: Sun, 3 Dec 2023 22:22:31 +0100 Subject: [PATCH] dev/core#4411 fix issue with user language --- .../CRM/Standaloneusers/BAO/User.php | 4 ++++ .../CRM/Standaloneusers/DAO/User.php | 8 +++++++- ext/standaloneusers/Civi/Standalone/Security.php | 16 ++++++++++++++++ .../ang/afformEditUserAccount.aff.html | 2 +- ext/standaloneusers/standaloneusers.php | 16 ++++++++++++++++ .../xml/schema/CRM/Standaloneusers/User.xml | 6 ++++++ 6 files changed, 50 insertions(+), 2 deletions(-) diff --git a/ext/standaloneusers/CRM/Standaloneusers/BAO/User.php b/ext/standaloneusers/CRM/Standaloneusers/BAO/User.php index 70f96fd1fb..2522b9d91f 100644 --- a/ext/standaloneusers/CRM/Standaloneusers/BAO/User.php +++ b/ext/standaloneusers/CRM/Standaloneusers/BAO/User.php @@ -29,4 +29,8 @@ class CRM_Standaloneusers_BAO_User extends CRM_Standaloneusers_DAO_User implemen $sess->set('lastAccess', time()); } + public static function getPreferredLanguages(): array { + return CRM_Core_I18n::uiLanguages(FALSE); + } + } diff --git a/ext/standaloneusers/CRM/Standaloneusers/DAO/User.php b/ext/standaloneusers/CRM/Standaloneusers/DAO/User.php index 8ebd081ab4..b1e6f21b31 100644 --- a/ext/standaloneusers/CRM/Standaloneusers/DAO/User.php +++ b/ext/standaloneusers/CRM/Standaloneusers/DAO/User.php @@ -6,7 +6,7 @@ * * Generated from standaloneusers/xml/schema/CRM/Standaloneusers/User.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:0b0cd1d01573ad0e5adc1a3e92f9638b) + * (GenCodeChecksum:bb2c741901a689ff804ab65d05c7795b) */ use CRM_Standaloneusers_ExtensionUtil as E; @@ -526,6 +526,12 @@ class CRM_Standaloneusers_DAO_User extends CRM_Core_DAO { 'entity' => 'User', 'bao' => 'CRM_Standaloneusers_DAO_User', 'localizable' => 0, + 'html' => [ + 'type' => 'Select', + ], + 'pseudoconstant' => [ + 'callback' => 'CRM_Standaloneusers_BAO_User::getPreferredLanguages', + ], 'add' => '2.1', ], 'password_reset_token' => [ diff --git a/ext/standaloneusers/Civi/Standalone/Security.php b/ext/standaloneusers/Civi/Standalone/Security.php index 34b4efca4e..2f041d671b 100644 --- a/ext/standaloneusers/Civi/Standalone/Security.php +++ b/ext/standaloneusers/Civi/Standalone/Security.php @@ -210,6 +210,8 @@ class Security { return FALSE; } + $this->applyLocaleFromUser($user); + // Note: random_int is more appropriate for cryptographical use than mt_rand // The long number is the max 32 bit value. return [$user['contact_id'], $user['id'], random_int(0, 2147483647)]; @@ -235,6 +237,7 @@ class Security { ])['values'][0]['contact_id'] ?? NULL; // Confusingly, Civi stores it's *Contact* ID as *userID* on the session. $session->set('userID', $contactID); + $this->applyLocaleFromUser($user); } } @@ -452,4 +455,17 @@ class Security { return $workflowMessage; } + /** + * Applies the locale from the user record. + * + * @param array $user + * @return void + */ + private function applyLocaleFromUser(array $user) { + $session = CRM_Core_Session::singleton(); + if (!empty($user['language'])) { + $session->set('lcMessages', $user['language']); + } + } + } diff --git a/ext/standaloneusers/ang/afformEditUserAccount.aff.html b/ext/standaloneusers/ang/afformEditUserAccount.aff.html index 53e67473d1..209509dde5 100644 --- a/ext/standaloneusers/ang/afformEditUserAccount.aff.html +++ b/ext/standaloneusers/ang/afformEditUserAccount.aff.html @@ -6,7 +6,7 @@ - + diff --git a/ext/standaloneusers/standaloneusers.php b/ext/standaloneusers/standaloneusers.php index 2b7b2e7931..fda5e61e72 100644 --- a/ext/standaloneusers/standaloneusers.php +++ b/ext/standaloneusers/standaloneusers.php @@ -10,6 +10,22 @@ require_once 'standaloneusers.civix.php'; use CRM_Standaloneusers_ExtensionUtil as E; // phpcs:enable +/** + * Hide the inherit CMS language on the Settings - Localization form. + * + * Implements hook_civicrm_buildForm(). + * + * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/ + */ +function standaloneusers_civicrm_buildForm($formName, CRM_Core_Form $form) { + // Administer / Localization / Languages, Currency, Locations + if ($formName == 'CRM_Admin_Form_Setting_Localization') { + if ($inheritLocaleElement = $form->getElement('inheritLocale')) { + $inheritLocaleElement->freeze(); + } + } +} + /** * Implements hook_civicrm_config(). * diff --git a/ext/standaloneusers/xml/schema/CRM/Standaloneusers/User.xml b/ext/standaloneusers/xml/schema/CRM/Standaloneusers/User.xml index fb5fd1ab21..8b9917f48c 100644 --- a/ext/standaloneusers/xml/schema/CRM/Standaloneusers/User.xml +++ b/ext/standaloneusers/xml/schema/CRM/Standaloneusers/User.xml @@ -183,6 +183,12 @@ varchar 5 UI language preferred by the given user/contact + + CRM_Standaloneusers_BAO_User::getPreferredLanguages + + + Select + 2.1 -- 2.25.1