44
55namespace Netgen \InformationCollection \Core \Factory ;
66
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 ;
915use Netgen \InformationCollection \API \Constants ;
16+ use Netgen \InformationCollection \API \ConfigurationConstants ;
1017use Netgen \InformationCollection \API \Exception \MissingValueException ;
11- use Netgen \InformationCollection \API \Factory \EmailContentFactoryInterface ;
1218use Netgen \InformationCollection \API \Value \DataTransfer \EmailContent ;
1319use Netgen \InformationCollection \API \Value \DataTransfer \TemplateContent ;
1420use 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 ;
1921use function trim ;
20- use const FILTER_VALIDATE_EMAIL ;
2122
22- class AutoResponderDataFactory implements EmailContentFactoryInterface
23+ class AutoResponderDataFactory extends EmailDataFactory
2324{
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+
2431 /**
2532 * Factory method.
33+ *
34+ * @param InformationCollected $value
35+ *
36+ * @return EmailContent
2637 */
2738 public function build (InformationCollected $ value ): EmailContent
2839 {
@@ -46,8 +57,12 @@ public function build(InformationCollected $value): EmailContent
4657
4758 /**
4859 * Returns resolved parameter.
60+ *
61+ * @param TemplateContent $data
62+ *
63+ * @return array
4964 */
50- protected function resolveRecipient (TemplateContent $ data ): array
65+ protected function resolveRecipient (TemplateContent $ data )
5166 {
5267 $ fields = $ data ->getEvent ()->getInformationCollectionStruct ()->getCollectedFields ();
5368 if ($ data ->getTemplateWrapper ()->hasBlock (Constants::FIELD_RECIPIENT )) {
@@ -64,9 +79,12 @@ protected function resolveRecipient(TemplateContent $data): array
6479 }
6580
6681 if (!empty ($ rendered )) {
82+
6783 $ emails = explode (', ' , $ rendered );
6884
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+ });
7088
7189 if (!empty ($ emails )) {
7290 return $ emails ;
@@ -79,16 +97,20 @@ protected function resolveRecipient(TemplateContent $data): array
7997 }
8098
8199 if (array_key_exists ($ field , $ fields )) {
82- return [$ fields [$ field ]->email ];
100+ return [$ fields [$ field ]->value -> email ];
83101 }
84102
85103 throw new MissingValueException ($ field );
86104 }
87105
88106 /**
89107 * Returns resolved parameter.
108+ *
109+ * @param TemplateContent $data
110+ *
111+ * @return string
90112 */
91- protected function resolveSubject (TemplateContent $ data ): string
113+ protected function resolveSubject (TemplateContent $ data )
92114 {
93115 $ fields = $ data ->getEvent ()->getInformationCollectionStruct ()->getCollectedFields ();
94116 if ($ data ->getTemplateWrapper ()->hasBlock (Constants::FIELD_AUTO_RESPONDER_SUBJECT )) {
@@ -105,8 +127,8 @@ protected function resolveSubject(TemplateContent $data): string
105127 }
106128
107129 $ 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 )
110132 ) {
111133 $ fieldValue = $ this ->translationHelper ->getTranslatedField ($ content , Constants::FIELD_AUTO_RESPONDER_SUBJECT );
112134
0 commit comments