PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.13
Yatra – Travel Booking & Tour Operator Software v3.0.13
3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 2.0.11 All 82 releases
yatra / app / Services / EmailTemplatePreviewService.php

EmailTemplatePreviewService.php in Yatra – Travel Booking & Tour Operator Software 3.0.13, at app/Services/EmailTemplatePreviewService.php

61 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Services;
6
7 /**
8 * Renders email preview HTML for any bundled template key (core settings + Pro default bodies).
9 */
10 final class EmailTemplatePreviewService
11 {
12 /**
13 * @return array{subject: string, body: string}
14 */
15 public static function render(
16 string $templateKey,
17 string $subjectTpl,
18 string $bodyTpl,
19 ?int $tripId = null
20 ): array {
21 $key = sanitize_key($templateKey);
22 if ($key === '' || !self::isPreviewable($key)) {
23 throw new \InvalidArgumentException(__('Unknown email template.', 'yatra'));
24 }
25
26 $samples = EmailTemplateSampleData::forTemplateKey($key, $tripId);
27 $coreType = TransactionalEmailTemplateService::coreTemplateKeyToType($key);
28
29 if ($coreType !== null) {
30 return TransactionalEmailTemplateService::renderWithStringTemplates(
31 $coreType,
32 $subjectTpl,
33 $bodyTpl,
34 $samples
35 );
36 }
37
38 $defaults = EmailTemplateDefaults::proSystemTemplate($key);
39 if ($defaults === null) {
40 throw new \InvalidArgumentException(__('Unknown email template.', 'yatra'));
41 }
42
43 $subjectOut = $subjectTpl !== ''
44 ? TransactionalEmailTemplateService::parseMergeTags($subjectTpl, $samples)
45 : TransactionalEmailTemplateService::parseMergeTags($defaults['subject'], $samples);
46
47 $bodyRaw = $bodyTpl !== '' ? $bodyTpl : $defaults['body'];
48 $bodyOut = TransactionalEmailTemplateService::parseMergeTags($bodyRaw, $samples);
49
50 return [
51 'subject' => $subjectOut,
52 'body' => $bodyOut,
53 ];
54 }
55
56 public static function isPreviewable(string $templateKey): bool
57 {
58 return EmailTemplateSampleData::isPreviewableTemplateKey(sanitize_key($templateKey));
59 }
60 }
61