|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Netgen\InformationCollection\Core\EmailDataProvider; |
|
4
|
|
|
|
|
5
|
|
|
use Netgen\InformationCollection\API\Action\EmailDataProviderInterface; |
|
6
|
|
|
use Netgen\InformationCollection\API\Value\Event\InformationCollected; |
|
7
|
|
|
use Symfony\Component\Mime\Email; |
|
8
|
|
|
use eZ\Publish\Core\MVC\ConfigResolverInterface; |
|
9
|
|
|
use Netgen\InformationCollection\Core\Action\EmailAction; |
|
10
|
|
|
use function array_key_exists; |
|
11
|
|
|
use eZ\Publish\API\Repository\Values\Content\Field; |
|
12
|
|
|
use eZ\Publish\Core\FieldType\BinaryFile\Value as BinaryFile; |
|
13
|
|
|
use eZ\Publish\Core\Helper\FieldHelper; |
|
14
|
|
|
use eZ\Publish\Core\Helper\TranslationHelper; |
|
15
|
|
|
use Netgen\InformationCollection\API\Value\DataTransfer\EmailContent; |
|
16
|
|
|
use Netgen\InformationCollection\API\Constants; |
|
17
|
|
|
use Netgen\InformationCollection\API\ConfigurationConstants; |
|
18
|
|
|
use Netgen\InformationCollection\API\Exception\MissingEmailBlockException; |
|
19
|
|
|
use Netgen\InformationCollection\API\Exception\MissingValueException; |
|
20
|
|
|
use Netgen\InformationCollection\API\Value\DataTransfer\TemplateContent; |
|
21
|
|
|
use function trim; |
|
22
|
|
|
use Twig\Environment; |
|
23
|
|
|
|
|
24
|
|
|
class DefaultProvider implements EmailDataProviderInterface |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var array |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $configResolver; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var \eZ\Publish\Core\Helper\TranslationHelper |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $translationHelper; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var \eZ\Publish\Core\Helper\FieldHelper |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $fieldHelper; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var \Twig\Environment |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $twig; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* EmailDataFactory constructor. |
|
48
|
|
|
* |
|
49
|
|
|
* @param array $config |
|
|
|
|
|
|
50
|
|
|
* @param \eZ\Publish\Core\Helper\TranslationHelper $translationHelper |
|
51
|
|
|
* @param \eZ\Publish\Core\Helper\FieldHelper $fieldHelper |
|
52
|
|
|
* @param \Twig\Environment $twig |
|
53
|
|
|
*/ |
|
54
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
|
|
55
|
|
|
ConfigResolverInterface $configResolver, |
|
56
|
|
|
TranslationHelper $translationHelper, |
|
57
|
|
|
FieldHelper $fieldHelper, |
|
58
|
|
|
Environment $twig |
|
59
|
|
|
) { |
|
60
|
|
|
$this->configResolver = $configResolver; |
|
|
|
|
|
|
61
|
|
|
$this->config = $this->configResolver->getParameter('action_config', 'netgen_information_collection')[EmailAction::$defaultName]; |
|
|
|
|
|
|
62
|
|
|
$this->translationHelper = $translationHelper; |
|
63
|
|
|
$this->fieldHelper = $fieldHelper; |
|
64
|
|
|
$this->twig = $twig; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Factory method. |
|
69
|
|
|
* |
|
70
|
|
|
* @param InformationCollected $value |
|
71
|
|
|
* |
|
72
|
|
|
* @return EmailContent |
|
73
|
|
|
*/ |
|
74
|
|
View Code Duplication |
public function build(InformationCollected $value): EmailContent |
|
|
|
|
|
|
75
|
|
|
{ |
|
76
|
|
|
$contentType = $value->getContentType(); |
|
77
|
|
|
|
|
78
|
|
|
$template = $this->resolveTemplate($contentType->identifier); |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
$templateWrapper = $this->twig->load($template); |
|
81
|
|
|
$data = new TemplateContent($value, $templateWrapper); |
|
82
|
|
|
|
|
83
|
|
|
$body = $this->resolveBody($data); |
|
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
return new EmailContent( |
|
86
|
|
|
$this->resolveEmail($data, Constants::FIELD_RECIPIENT), |
|
|
|
|
|
|
87
|
|
|
$this->resolveEmail($data, Constants::FIELD_SENDER), |
|
|
|
|
|
|
88
|
|
|
$this->resolve($data, Constants::FIELD_SUBJECT), |
|
|
|
|
|
|
89
|
|
|
$body, |
|
90
|
|
|
$this->resolveAttachments($contentType->identifier, $value->getInformationCollectionStruct()->getFieldsData()) |
|
|
|
|
|
|
91
|
|
|
); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function provide(InformationCollected $value): Email |
|
95
|
|
|
{ |
|
96
|
|
|
return new Email(); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.