Skip to content

Commit 2f65cc5

Browse files
author
René Hrdina
committed
feat: fix auto_responder action
1 parent ddcafee commit 2f65cc5

File tree

2 files changed

+47
-28
lines changed

2 files changed

+47
-28
lines changed

lib/Core/Factory/AutoResponderDataFactory.php

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,36 @@
44

55
namespace 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;
915
use Netgen\InformationCollection\API\Constants;
16+
use Netgen\InformationCollection\API\ConfigurationConstants;
1017
use Netgen\InformationCollection\API\Exception\MissingValueException;
11-
use Netgen\InformationCollection\API\Factory\EmailContentFactoryInterface;
1218
use Netgen\InformationCollection\API\Value\DataTransfer\EmailContent;
1319
use Netgen\InformationCollection\API\Value\DataTransfer\TemplateContent;
1420
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;
1921
use 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

lib/Resources/config/actions.yml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@ services:
33
class: Netgen\InformationCollection\Core\Action\ActionRegistry
44
arguments:
55
- !tagged_iterator netgen_information_collection.action
6-
- "@netgen_information_collection.action.config_utility"
6+
- '@Netgen\InformationCollection\Core\Action\ConfigurationUtility'
77
- "@logger"
88
- "@event_dispatcher"
99
calls:
1010
- [setDebug, ['%kernel.debug%']]
1111

12-
netgen_information_collection.action.config_utility:
13-
class: Netgen\InformationCollection\Core\Action\ConfigurationUtility
12+
Netgen\InformationCollection\Core\Action\ConfigurationUtility:
1413
arguments:
15-
- "@ibexa.config.resolver"
14+
- '@ibexa.config.resolver'
1615

17-
netgen_information_collection.action.db:
18-
class: Netgen\InformationCollection\Core\Action\DatabaseAction
16+
Netgen\InformationCollection\Core\Action\DatabaseAction:
1917
arguments:
2018
- '@netgen_information_collection.api.service'
2119
tags:
@@ -28,10 +26,9 @@ services:
2826
tags:
2927
- { name: netgen_information_collection.action }
3028

31-
# netgen_information_collection.action.auto_responder:
32-
# class: Netgen\InformationCollection\Core\Action\AutoResponderAction
33-
# arguments:
34-
# - '@netgen_information_collection.factory.auto_responder_data'
35-
# - '@netgen_information_collection.mailer'
36-
# tags:
37-
# - { name: netgen_information_collection.action, alias: auto_responder }
29+
Netgen\InformationCollection\Core\Action\AutoResponderAction:
30+
arguments:
31+
- '@Netgen\InformationCollection\API\MailerInterface'
32+
- '@Netgen\InformationCollection\Core\EmailDataProvider\AutoResponderProvider'
33+
tags:
34+
- { name: netgen_information_collection.action }

0 commit comments

Comments
 (0)