From 01b6270ba465914d7673ef3778940f76ad048506 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 22 Jun 2022 15:29:27 +1200 Subject: [PATCH] Pass language into msg_admin api calls --- Civi/Api4/Action/WorkflowMessage/Render.php | 15 +++++++++++++-- ext/message_admin/ang/crmMsgadm/Edit.js | 2 +- ext/message_admin/ang/crmMsgadm/Preview.js | 10 +++++++++- tests/phpunit/api/v4/Entity/ConformanceTest.php | 1 + 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Civi/Api4/Action/WorkflowMessage/Render.php b/Civi/Api4/Action/WorkflowMessage/Render.php index 86611072b9..c645374ba8 100644 --- a/Civi/Api4/Action/WorkflowMessage/Render.php +++ b/Civi/Api4/Action/WorkflowMessage/Render.php @@ -75,13 +75,24 @@ class Render extends \Civi\Api4\Generic\AbstractAction { public function _run(\Civi\Api4\Generic\Result $result) { $this->validateValues(); - + global $moneyFormatLocale; + $separatorConfig = \CRM_Utils_Constant::value('IGNORE_SEPARATOR_CONFIG'); + $originalValue = $moneyFormatLocale; + + if ($this->getTranslationLanguage()) { + // Passing in translation language forces money formatting, useful when the + // template is previewed before being saved. + $moneyFormatLocale = $this->getTranslationLanguage(); + putenv('IGNORE_SEPARATOR_CONFIG=' . 1); + } $r = \CRM_Core_BAO_MessageTemplate::renderTemplate([ 'model' => $this->_model, 'messageTemplate' => $this->getMessageTemplate(), 'messageTemplateId' => $this->getMessageTemplateId(), + 'language' => $this->getPreferredLanguage(), ]); - + $moneyFormatLocale = $originalValue; + putenv('IGNORE_SEPARATOR_CONFIG=' . $separatorConfig); $result[] = \CRM_Utils_Array::subset($r, ['subject', 'html', 'text']); } diff --git a/ext/message_admin/ang/crmMsgadm/Edit.js b/ext/message_admin/ang/crmMsgadm/Edit.js index 6e01a76a7a..ccba2dfcac 100644 --- a/ext/message_admin/ang/crmMsgadm/Edit.js +++ b/ext/message_admin/ang/crmMsgadm/Edit.js @@ -271,6 +271,7 @@ crmApi4({ examples: ['ExampleData', 'get', { // FIXME: workflow name + language: $ctrl.lang, where: [["tags", "CONTAINS", "preview"], ["name", "LIKE", "workflow/" + $ctrl.records.main.workflow_name + "/%"]], select: ['name', 'title', 'data'] }], @@ -279,7 +280,6 @@ format: 'example' }] }).then(function(resp) { - console.log('resp',resp); if ((!resp.examples || resp.examples.length === 0) && resp.adhoc) { // In the future, if Preview dialog allows editing adhoc examples, then we can show the dialog. But for now, it won't work without explicit examples. crmUiAlert({ diff --git a/ext/message_admin/ang/crmMsgadm/Preview.js b/ext/message_admin/ang/crmMsgadm/Preview.js index 82b994c27d..1b202c577d 100644 --- a/ext/message_admin/ang/crmMsgadm/Preview.js +++ b/ext/message_admin/ang/crmMsgadm/Preview.js @@ -1,10 +1,14 @@ (function(angular, $, _) { - angular.module('crmMsgadm').controller('MsgtpluiPreviewCtrl', function($scope, crmUiHelp, crmStatus, crmApi4, crmUiAlert, $timeout, $q, dialogService) { + angular.module('crmMsgadm').controller('MsgtpluiPreviewCtrl', function($scope, crmUiHelp, crmStatus, crmApi4, crmUiAlert, $timeout, $q, dialogService, $location) { var ts = $scope.ts = CRM.ts('crmMsgadm'); var hs = $scope.hs = crmUiHelp({file: 'CRM/MessageAdmin/crmMsgadm'}); // See: templates/CRM/MessageAdmin/crmMsgadm.hlp var $ctrl = this, model = $scope.model; + var args = $location.search(); + if (args.lang) { + $ctrl.lang = args.lang; + } $ctrl.exampleId = parseInt(_.findKey(model.examples, {name: model.exampleName})); $ctrl.revisionId = parseInt(_.findKey(model.revisions, {name: model.revisionName})); @@ -35,6 +39,7 @@ dlgModel.refresh = function(){ return crmApi4('ExampleData', 'get', { where: [["name", "=", model.examples[$ctrl.exampleId].name]], + language: $ctrl.lang, select: ['name', 'file', 'title', 'data'] }).then(function(response){ dlgModel.title = ts('Example: %1', {1: response[0].title || response[0].name}); @@ -64,6 +69,7 @@ function requestStoredExample() { return crmApi4('ExampleData', 'get', { where: [["name", "=", model.examples[$ctrl.exampleId].name]], + language: $ctrl.lang, select: ['data'] }).then(function(response) { return response[0].data; @@ -82,6 +88,8 @@ rendering.then(function(exampleData) { var filteredData = model.filterData ? model.filterData(exampleData) : exampleData; return crmApi4('WorkflowMessage', 'render', { + language: $ctrl.lang, + translationLanguage: $ctrl.lang, workflow: filteredData.workflow, values: filteredData.modelProps, messageTemplate: model.revisions[$ctrl.revisionId].rec diff --git a/tests/phpunit/api/v4/Entity/ConformanceTest.php b/tests/phpunit/api/v4/Entity/ConformanceTest.php index f7b43a04cd..773012b4f5 100644 --- a/tests/phpunit/api/v4/Entity/ConformanceTest.php +++ b/tests/phpunit/api/v4/Entity/ConformanceTest.php @@ -67,6 +67,7 @@ class ConformanceTest extends Api4TestBase implements HookInterface { 'civicrm_participant', 'civicrm_batch', 'civicrm_product', + 'civicrm_translation', ]; $this->cleanup(['tablesToTruncate' => $tablesToTruncate]); parent::tearDown(); -- 2.25.1