diff --git a/application/Espo/Controllers/EmailTemplate.php b/application/Espo/Controllers/EmailTemplate.php index aa4ba950d3..0937775e82 100644 --- a/application/Espo/Controllers/EmailTemplate.php +++ b/application/Espo/Controllers/EmailTemplate.php @@ -25,7 +25,7 @@ * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. - ************************************************************************/ + ************************************************************************/ namespace Espo\Controllers; @@ -34,17 +34,19 @@ use \Espo\Core\Exceptions\Error; class EmailTemplate extends \Espo\Core\Controllers\Record { public function actionParse($params, $data, $request) - { + { $id = $request->get('id'); $emailAddress = $request->get('emailAddress'); if (empty($id)) { throw new Error(); } - + return $this->getRecordService()->parse($id, array( 'emailAddress' => $request->get('emailAddress'), 'parentType' => $request->get('parentType'), 'parentId' => $request->get('parentId'), + 'relatedType' => $request->get('relatedType'), + 'relatedId' => $request->get('relatedId') ), true); } diff --git a/application/Espo/Services/EmailTemplate.php b/application/Espo/Services/EmailTemplate.php index 52d12ba6e0..c9512073ce 100644 --- a/application/Espo/Services/EmailTemplate.php +++ b/application/Espo/Services/EmailTemplate.php @@ -110,6 +110,13 @@ class EmailTemplate extends Record } } + if (!empty($params['relatedId']) && !empty($params['relatedType'])) { + $related = $this->getEntityManager()->getEntity($params['relatedType'], $params['relatedId']); + if ($related) { + $entityHash[$related->getEntityType()] = $related; + } + } + $subject = $emailTemplate->get('subject'); $body = $emailTemplate->get('body'); diff --git a/client/src/views/email/fields/select-template.js b/client/src/views/email/fields/select-template.js index d4e082f507..e79974eaf4 100644 --- a/client/src/views/email/fields/select-template.js +++ b/client/src/views/email/fields/select-template.js @@ -65,6 +65,8 @@ Espo.define('views/email/fields/select-template', 'views/fields/link', function emailAddress: emailAddress, parentType: this.model.get('parentType'), parentId: this.model.get('parentId'), + relatedType: this.model.get('relatedType'), + relatedId: this.model.get('relatedId') }, success: function (data) { this.model.trigger('insert-template', data);