|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* Copyright (C) |
|
6
|
|
|
* Nathan Boiron <[email protected]> |
|
7
|
|
|
* Romain Canon <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* This file is part of the TYPO3 NotiZ project. |
|
10
|
|
|
* It is free software; you can redistribute it and/or modify it |
|
11
|
|
|
* under the terms of the GNU General Public License, either |
|
12
|
|
|
* version 3 of the License, or any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* For the full copyright and license information, see: |
|
15
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace CuyZ\Notiz\Controller\Backend\Manager\Notification; |
|
19
|
|
|
|
|
20
|
|
|
use CuyZ\Notiz\Domain\Notification\Email\Application\EntityEmail\EntityEmailNotification; |
|
21
|
|
|
use CuyZ\Notiz\Domain\Notification\Email\Application\EntityEmail\Service\EntityEmailTemplateBuilder; |
|
22
|
|
|
use CuyZ\Notiz\Domain\Property\Email; |
|
23
|
|
|
use Throwable; |
|
24
|
|
|
|
|
25
|
|
|
class ShowEntityEmailController extends ShowNotificationController |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var EntityEmailNotification |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $notification; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @inheritdoc |
|
34
|
|
|
*/ |
|
35
|
|
|
public function showAction() |
|
36
|
|
|
{ |
|
37
|
|
|
parent::showAction(); |
|
38
|
|
|
|
|
39
|
|
|
if ($this->notification->hasEventDefinition()) { |
|
40
|
|
|
$eventDefinition = $this->notification->getEventDefinition(); |
|
41
|
|
|
$emailProperties = $eventDefinition->getPropertyDefinition(Email::class, $this->notification); |
|
42
|
|
|
|
|
43
|
|
|
$this->view->assign('emailProperties', $emailProperties); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* This action is called to show a preview of the shown email notification. |
|
49
|
|
|
* |
|
50
|
|
|
* An event is simulated in order to render the original Fluid template used |
|
51
|
|
|
* by the notification. Example values may be added to simulate fake markers |
|
52
|
|
|
* in the view. |
|
53
|
|
|
* |
|
54
|
|
|
* @return string|null [PHP 7.1] |
|
55
|
|
|
*/ |
|
56
|
|
|
public function previewAction() |
|
57
|
|
|
{ |
|
58
|
|
|
try { |
|
59
|
|
|
return $this->getEmailPreview(); |
|
60
|
|
|
} catch (Throwable $e) { |
|
61
|
|
|
return null; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* This action is used to show an error |
|
67
|
|
|
*/ |
|
68
|
|
|
public function previewErrorAction() |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->getEmailPreview(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function getEmailPreview(): string |
|
77
|
|
|
{ |
|
78
|
|
|
if (!$this->notification->hasEventDefinition()) { |
|
79
|
|
|
return $this->notification->getBody(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** @var EntityEmailTemplateBuilder $entityEmailTemplateBuilder */ |
|
83
|
|
|
$entityEmailTemplateBuilder = $this->objectManager->get(EntityEmailTemplateBuilder::class, $this->getPreviewPayload()); |
|
84
|
|
|
|
|
85
|
|
|
return $entityEmailTemplateBuilder->getBody(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return string |
|
90
|
|
|
*/ |
|
91
|
|
|
public function getNotificationDefinitionIdentifier(): string |
|
92
|
|
|
{ |
|
93
|
|
|
return EntityEmailNotification::getDefinitionIdentifier(); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|