X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=Civi%2FAPI%2FSubscriber%2FI18nSubscriber.php;h=5b60b1eb7075ecf57f364ead06b64ab2c54fc854;hb=3e20c1acb397d6dfe89fe394a4f4e9b023142f80;hp=1446e242f89ee8786d1ccd2a9e1bb7aa6e910ca5;hpb=5afcf74389296764bd92ed3bc3b2f5f209933bfe;p=civicrm-core.git diff --git a/Civi/API/Subscriber/I18nSubscriber.php b/Civi/API/Subscriber/I18nSubscriber.php index 1446e242f8..5b60b1eb70 100644 --- a/Civi/API/Subscriber/I18nSubscriber.php +++ b/Civi/API/Subscriber/I18nSubscriber.php @@ -3,7 +3,7 @@ +--------------------------------------------------------------------+ | CiviCRM version 5 | +--------------------------------------------------------------------+ - | Copyright CiviCRM LLC (c) 2004-2018 | + | Copyright CiviCRM LLC (c) 2004-2019 | +--------------------------------------------------------------------+ | This file is a part of CiviCRM. | | | @@ -35,16 +35,19 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; * @package Civi\API\Subscriber */ class I18nSubscriber implements EventSubscriberInterface { + /** * @return array */ public static function getSubscribedEvents() { - return array( - Events::PREPARE => array('onApiPrepare', Events::W_MIDDLE), - ); + return [ + Events::PREPARE => ['onApiPrepare', Events::W_MIDDLE], + ]; } /** + * Support multi-lingual requests + * * @param \Civi\API\Event\Event $event * API preparation event. * @@ -53,8 +56,14 @@ class I18nSubscriber implements EventSubscriberInterface { public function onApiPrepare(\Civi\API\Event\Event $event) { $apiRequest = $event->getApiRequest(); - // support multi-lingual requests - if ($language = \CRM_Utils_Array::value('option.language', $apiRequest['params'])) { + $params = $apiRequest['params']; + if ($apiRequest['version'] < 4) { + $language = !empty($params['options']['language']) ? $params['options']['language'] : \CRM_Utils_Array::value('option.language', $params); + } + else { + $language = \CRM_Utils_Array::value('language', $params); + } + if ($language) { $this->setLocale($language); } } @@ -80,7 +89,7 @@ class I18nSubscriber implements EventSubscriberInterface { // on multi-lang sites based on request and civicrm_uf_match if ($multiLang) { $config = \CRM_Core_Config::singleton(); - $languageLimit = array(); + $languageLimit = []; if (isset($config->languageLimit) and $config->languageLimit) { $languageLimit = $config->languageLimit; } @@ -89,7 +98,7 @@ class I18nSubscriber implements EventSubscriberInterface { $lcMessages = $lcMessagesRequest; } else { - throw new \API_Exception(ts('Language not enabled: %1', array(1 => $lcMessagesRequest))); + throw new \API_Exception(ts('Language not enabled: %1', [1 => $lcMessagesRequest])); } }