From a23ac54da004ff51acfc7b9cbb62de05b402bb57 Mon Sep 17 00:00:00 2001 From: yuri Date: Tue, 20 Oct 2015 15:32:01 +0300 Subject: [PATCH] email template: translate enum --- application/Espo/Services/EmailTemplate.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/application/Espo/Services/EmailTemplate.php b/application/Espo/Services/EmailTemplate.php index 02c692b0f1..43df24fadf 100644 --- a/application/Espo/Services/EmailTemplate.php +++ b/application/Espo/Services/EmailTemplate.php @@ -36,6 +36,7 @@ class EmailTemplate extends Record { $this->dependencies[] = 'fileManager'; $this->dependencies[] = 'dateTime'; + $this->dependencies[] = 'language'; } protected function getFileManager() @@ -48,6 +49,11 @@ class EmailTemplate extends Record return $this->injections['dateTime']; } + protected function getLanguage() + { + return $this->getInjection('language'); + } + public function parseTemplate(Entity $emailTemplate, array $params = array(), $copyAttachments = false) { $entityHash = array(); @@ -160,10 +166,16 @@ class EmailTemplate extends Record continue; } - if ($entity->fields[$field]['type'] == 'date') { - $value = $this->getDateTime()->convertSystemDateToGlobal($value); - } else if ($entity->fields[$field]['type'] == 'datetime') { - $value = $this->getDateTime()->convertSystemDateTimeToGlobal($value); + $fieldType = $this->getMetadata()->get('entityDefs.' . $entity->getEntityType() .'.fields.' . $field . '.type'); + + if ($fieldType === 'enum') { + $value = $this->getLanguage()->translateOption($value, $field, $entity->getEntityType()); + } else { + if ($entity->fields[$field]['type'] == 'date') { + $value = $this->getDateTime()->convertSystemDateToGlobal($value); + } else if ($entity->fields[$field]['type'] == 'datetime') { + $value = $this->getDateTime()->convertSystemDateTimeToGlobal($value); + } } $text = str_replace('{' . $type . '.' . $field . '}', $value, $text); }