4
4
5
5
namespace Netgen \InformationCollection \Core \Factory ;
6
6
7
- use Ibexa \Contracts \Core \Repository \Values \Content \Field ;
8
- use Netgen \InformationCollection \API \ConfigurationConstants ;
7
+ use eZ \Publish \Core \Helper \FieldHelper ;
8
+ use eZ \Publish \Core \Helper \TranslationHelper ;
9
+ use eZ \Publish \Core \MVC \ConfigResolverInterface ;
10
+ use Netgen \InformationCollection \Core \Action \AutoResponderAction ;
11
+ use Netgen \InformationCollection \Core \Action \EmailAction ;
12
+ use Twig \Environment ;
13
+ use function array_key_exists ;
14
+ use eZ \Publish \API \Repository \Values \Content \Field ;
9
15
use Netgen \InformationCollection \API \Constants ;
16
+ use Netgen \InformationCollection \API \ConfigurationConstants ;
10
17
use Netgen \InformationCollection \API \Exception \MissingValueException ;
11
- use Netgen \InformationCollection \API \Factory \EmailContentFactoryInterface ;
12
18
use Netgen \InformationCollection \API \Value \DataTransfer \EmailContent ;
13
19
use Netgen \InformationCollection \API \Value \DataTransfer \TemplateContent ;
14
20
use Netgen \InformationCollection \API \Value \Event \InformationCollected ;
15
- use function array_filter ;
16
- use function array_key_exists ;
17
- use function explode ;
18
- use function filter_var ;
19
21
use function trim ;
20
- use const FILTER_VALIDATE_EMAIL ;
21
22
22
- class AutoResponderDataFactory implements EmailContentFactoryInterface
23
+ class AutoResponderDataFactory extends EmailDataFactory
23
24
{
25
+ public function __construct (ConfigResolverInterface $ configResolver , TranslationHelper $ translationHelper , FieldHelper $ fieldHelper , Environment $ twig )
26
+ {
27
+ parent ::__construct ($ configResolver , $ translationHelper , $ fieldHelper , $ twig );
28
+ $ this ->config = $ this ->configResolver ->getParameter ('action_config ' , 'netgen_information_collection ' )[AutoResponderAction::$ defaultName ];
29
+ }
30
+
24
31
/**
25
32
* Factory method.
33
+ *
34
+ * @param InformationCollected $value
35
+ *
36
+ * @return EmailContent
26
37
*/
27
38
public function build (InformationCollected $ value ): EmailContent
28
39
{
@@ -46,8 +57,12 @@ public function build(InformationCollected $value): EmailContent
46
57
47
58
/**
48
59
* Returns resolved parameter.
60
+ *
61
+ * @param TemplateContent $data
62
+ *
63
+ * @return array
49
64
*/
50
- protected function resolveRecipient (TemplateContent $ data ): array
65
+ protected function resolveRecipient (TemplateContent $ data )
51
66
{
52
67
$ fields = $ data ->getEvent ()->getInformationCollectionStruct ()->getCollectedFields ();
53
68
if ($ data ->getTemplateWrapper ()->hasBlock (Constants::FIELD_RECIPIENT )) {
@@ -64,9 +79,12 @@ protected function resolveRecipient(TemplateContent $data): array
64
79
}
65
80
66
81
if (!empty ($ rendered )) {
82
+
67
83
$ emails = explode (', ' , $ rendered );
68
84
69
- $ emails = array_filter ($ emails , static fn ($ var ) => filter_var ($ var , FILTER_VALIDATE_EMAIL ));
85
+ $ emails = array_filter ($ emails , function ($ var ) {
86
+ return filter_var ($ var , FILTER_VALIDATE_EMAIL );
87
+ });
70
88
71
89
if (!empty ($ emails )) {
72
90
return $ emails ;
@@ -79,16 +97,20 @@ protected function resolveRecipient(TemplateContent $data): array
79
97
}
80
98
81
99
if (array_key_exists ($ field , $ fields )) {
82
- return [$ fields [$ field ]->email ];
100
+ return [$ fields [$ field ]->value -> email ];
83
101
}
84
102
85
103
throw new MissingValueException ($ field );
86
104
}
87
105
88
106
/**
89
107
* Returns resolved parameter.
108
+ *
109
+ * @param TemplateContent $data
110
+ *
111
+ * @return string
90
112
*/
91
- protected function resolveSubject (TemplateContent $ data ): string
113
+ protected function resolveSubject (TemplateContent $ data )
92
114
{
93
115
$ fields = $ data ->getEvent ()->getInformationCollectionStruct ()->getCollectedFields ();
94
116
if ($ data ->getTemplateWrapper ()->hasBlock (Constants::FIELD_AUTO_RESPONDER_SUBJECT )) {
@@ -105,8 +127,8 @@ protected function resolveSubject(TemplateContent $data): string
105
127
}
106
128
107
129
$ content = $ data ->getContent ();
108
- if (array_key_exists (Constants::FIELD_AUTO_RESPONDER_SUBJECT , $ content ->fields )
109
- && !$ this ->fieldHelper ->isFieldEmpty ($ content , Constants::FIELD_AUTO_RESPONDER_SUBJECT )
130
+ if (array_key_exists (Constants::FIELD_AUTO_RESPONDER_SUBJECT , $ content ->fields ) &&
131
+ !$ this ->fieldHelper ->isFieldEmpty ($ content , Constants::FIELD_AUTO_RESPONDER_SUBJECT )
110
132
) {
111
133
$ fieldValue = $ this ->translationHelper ->getTranslatedField ($ content , Constants::FIELD_AUTO_RESPONDER_SUBJECT );
112
134
0 commit comments