Merge pull request #14252 from jitendrapurohit/core-961
[civicrm-core.git] / Civi / API / Subscriber / I18nSubscriber.php
index 02c4d7e79799d52ce2cc2fa20da36f014ac2f5a1..335bc823afa5bf0fc09362ccf4b4edc9f66e7089 100644 (file)
@@ -98,38 +98,22 @@ class I18nSubscriber implements EventSubscriberInterface {
    * Sets the tsLocale and dbLocale for multi-lingual sites.
    * Some code duplication from CRM/Core/BAO/ConfigSetting.php retrieve()
    * to avoid regressions from refactoring.
-   * @param $lcMessagesRequest
+   * @param string $lcMessages
    * @param int $requestId
    * @throws \API_Exception
    */
-  public function setLocale($lcMessagesRequest, $requestId) {
-    // We must validate whether the locale is valid, otherwise setting a bad
-    // dbLocale could probably lead to sql-injection.
+  public function setLocale($lcMessages, $requestId) {
     $domain = new \CRM_Core_DAO_Domain();
     $domain->id = \CRM_Core_Config::domainID();
     $domain->find(TRUE);
 
-    // are we in a multi-language setup?
-    $multiLang = $domain->locales ? TRUE : FALSE;
-    $lcMessages = NULL;
-
-    // on multi-lang sites based on request and civicrm_uf_match
-    if ($multiLang) {
-      $config = \CRM_Core_Config::singleton();
-      $languageLimit = [];
-      if (isset($config->languageLimit) and $config->languageLimit) {
-        $languageLimit = $config->languageLimit;
-      }
-
-      if (in_array($lcMessagesRequest, array_keys($languageLimit))) {
-        $lcMessages = $lcMessagesRequest;
+    // Check if the site is multi-lingual
+    if ($domain->locales && $lcMessages) {
+      // Validate language, otherwise a bad dbLocale could probably lead to sql-injection.
+      if (!array_key_exists($lcMessages, \Civi::settings()->get('languageLimit'))) {
+        throw new \API_Exception(ts('Language not enabled: %1', [1 => $lcMessages]));
       }
-      else {
-        throw new \API_Exception(ts('Language not enabled: %1', [1 => $lcMessagesRequest]));
-      }
-    }
 
-    if ($lcMessages) {
       global $dbLocale;
       global $tsLocale;