Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: introduce ibexa 3 compatibility #80

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion bundle/Controller/Admin/Export/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace Netgen\Bundle\InformationCollectionBundle\Controller\Admin\Export;

use eZ\Publish\Core\MVC\Symfony\Security\Authorization\Attribute;
use Netgen\Bundle\InformationCollectionBundle\Form\ExportType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Netgen\InformationCollection\API\Value\Export\ExportCriteria;
use Netgen\InformationCollection\API\Service\Exporter;
use Netgen\InformationCollection\Core\Export\ExportResponseFormatterRegistry;
use Symfony\Component\HttpFoundation\Request;
use Netgen\InformationCollection\Form\Type\ExportType;
use eZ\Publish\API\Repository\ContentService;

final class Export extends AbstractController
Expand Down
2 changes: 1 addition & 1 deletion bundle/Controller/Admin/TreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected function getCollections(Content $content, $isRoot = false)
return array(
'id' => $content->getContent()->id,
'parent' => $isRoot ? '#' : '0',
'text' => $content->getContent()->getName($languages[0]) . ' (' . strval($count->getCount()) . ')',
'text' => $content->getContent()->getName(in_array($languages[0], $content->getContent()->getVersionInfo()->languageCodes) ? $languages[0] : null) . ' (' . strval($count->getCount()) . ')',
'children' => false,
'a_attr' => array(
'href' => $this->router->generate('netgen_information_collection.route.admin.collection_list', ['contentId' => $content->getContent()->id]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public function load(array $configs, ContainerBuilder $container)
$libResourceLoader->load('services.yml');
$libResourceLoader->load('parameters.yml');
$libResourceLoader->load('default_settings.yml');
$libResourceLoader->load('email_data_providers.yml');
$libResourceLoader->load('mailers.yml');


$this->processSemanticConfig($container, $config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class InformationCollectionMapper
*/
public function mapToFormData(Content $content, Location $location, ContentType $contentType)
{
$fields = $content->getFieldsByLanguage($content->contentInfo->mainLanguageCode);
$fields = $content->getFieldsByLanguage();

$informationCollectionFields = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)

foreach ($struct->getFieldsData() as $fieldsDatum) {
$builder->add($fieldsDatum->fieldDefinition->identifier, InformationCollectionFieldType::class, [
//'label' => false,
'languageCode' => $options['languageCode'],
'mainLanguageCode' => $options['mainLanguageCode'],
]);
Expand Down
7 changes: 5 additions & 2 deletions bundle/Listener/CaptchaValidationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ public function onPostSubmit(FormEvent $event)
->getConfig()
->getOption('captcha_value');

// $request = $this->requestStack->getCurrentRequest();
$request = Request::createFromGlobals();
$request = $this->requestStack->getCurrentRequest();
// $request = Request::createFromGlobals();

$submittedHostName = $request->getHost();
$captchaValue->getInnerCaptcha()->setExpectedHostname($submittedHostName);

$text = 'The captcha is invalid. Please try again.';

Expand Down
6 changes: 6 additions & 0 deletions bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ services:
- '@request_stack'
- '@netgen_information_collection.captcha.service'
- '@translator'

Netgen\InformationCollection\API\Service\CaptchaService:
alias: Netgen\InformationCollection\Core\Service\CaptchaService

eZ\Publish\Core\Helper\TranslationHelper:
alias: ezpublish.translation_helper
10 changes: 9 additions & 1 deletion bundle/Resources/views/admin/content_fields.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@
{% block ezboolean_field %}
{% apply spaceless %}
{% set field_value = attribute.value %}
{% if field_value %}
{% if field_value.dataInt %}
{{ 'field_value.yes'|trans }}
{% else %}
{{ 'field_value.no'|trans }}
{% endif %}
{% endapply %}
{% endblock %}

{% block enhancedezbinaryfile_field %}
{% apply spaceless %}
<a href={{ path('netgen_enhancedezbinaryfile.route.download_binary_file', {infocollectionAttributeId: attribute.id}) }}>
Download
</a>
{% endapply %}
{% endblock %}

{% block default_field %}
{% apply spaceless %}
{{ attribute.value }}
Expand Down
2 changes: 1 addition & 1 deletion bundle/Resources/views/admin/view.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<input id="{{ attribute.fieldDefinition.id }}" name="FieldId[]" value="{{ attribute.fieldDefinition.id }}" title="Select collections for removal." type="checkbox" data-enable="Item">
<label for="{{ attribute.fieldDefinition.id }}">
<span class="attribute-name">
{{ ez_field_name(content, attribute.field.fieldDefIdentifier) }}:
{{ ez_field_name(content, attribute.fieldDefinition.identifier) }}:
</span>
<span class="attribute-value">
{{ info_collection_render_field(collection, attribute) }}
Expand Down
15 changes: 8 additions & 7 deletions bundle/Resources/views/email/default.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{# event \Netgen\Bundle\InformationCollectionBundle\Event\InformationCollected #}
{# content \eZ\Publish\API\Repository\Values\Content\Content #}
{# @var event \Netgen\InformationCollection\API\Value\Event\InformationCollected #}
{# @var content \eZ\Publish\API\Repository\Values\Content\Content #}
{# @var content_type \eZ\Publish\API\Repository\Values\ContentType\ContentType #}

{% block email %}

Expand All @@ -12,19 +13,19 @@
{{ ez_field_name(content, field_name) }}:
</div>
<div class="value">
{% if content_type.fieldDefinitionsByIdentifier[field_name].fieldTypeIdentifier == 'ezselection' %}
{% set selectionArray=field_value|split('-') %}
{% if content_type.fieldDefinitions.get(field_name).fieldTypeIdentifier == 'ezselection' %}
{% set selectionArray=field_value.value|split('-') %}
{% if selectionArray|length > 1 %}<ul>{% endif %}
{% for selected_key, selected_value in selectionArray %}
{% if loop.length == 1 %}
{{ content_type.fieldDefinitionsByIdentifier[field_name].fieldSettings.options[selected_value] }}<br>
{{ content_type.fieldDefinitions.get(field_name).fieldSettings.options[selected_value] }}<br>
{% else %}
<li>{{ content_type.fieldDefinitionsByIdentifier[field_name].fieldSettings.options[selected_value] }}</li><br>
<li>{{ content_type.fieldDefinitions.get(field_name).fieldSettings.options[selected_value] }}</li><br>
{% endif %}
{% endfor %}
{% if selectionArray|length > 1 %}</ul>{% endif %}
{% else %}
{{ field_value }}
{{ field_value.value }}
{% endif %}
</div><br>
</div>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}
],
"require": {
"php": "^7.3",
"php": ">=7.3",
"ext-pdo": "*",
"doctrine/orm": "^2.5",
"ezsystems/ezplatform-admin-ui": "^2.0",
Expand Down
2 changes: 0 additions & 2 deletions lib/API/Value/Captcha/ReCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public function isValid(Request $request): bool
$clientIp
);

dump($response);

return $response->isSuccess();
}

Expand Down
6 changes: 3 additions & 3 deletions lib/API/Value/InformationCollectionStruct.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use eZ\Publish\API\Repository\Values\Content\Content;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
use EzSystems\RepositoryForms\Data\Content\FieldData;
use EzSystems\EzPlatformContentForms\Data\Content\FieldData;

final class InformationCollectionStruct extends ValueObject
{
Expand Down Expand Up @@ -82,15 +82,15 @@ public function getContentType(): ContentType
}

/**
* @return \EzSystems\RepositoryForms\Data\Content\FieldData[]
* @return FieldData[]
*/
public function getFieldsData(): array
{
return $this->fields;
}

/**
* @return \EzSystems\RepositoryForms\Data\Content\FieldData[]
* @return FieldData[]
*/
public function getCollectedFields(): array
{
Expand Down
20 changes: 8 additions & 12 deletions lib/Core/Action/BaseEmailAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Netgen\InformationCollection\API\Exception\EmailNotSentException;
use Netgen\InformationCollection\API\MailerInterface;
use Netgen\InformationCollection\API\Value\Event\InformationCollected;
use Netgen\InformationCollection\Core\EmailDataProvider\DefaultProvider;
use Netgen\InformationCollection\Core\Factory\BaseEmailDataFactory;

abstract class BaseEmailAction implements ActionInterface
Expand All @@ -18,31 +19,26 @@ abstract class BaseEmailAction implements ActionInterface
protected $mailer;

/**
* @var \Netgen\InformationCollection\Core\Factory\BaseEmailDataFactory
* @var DefaultProvider
*/
protected $factory;
protected $emailDataProvider;

/**
* EmailAction constructor.
*
* @param \Netgen\InformationCollection\API\MailerInterface $mailer
* @param \Netgen\InformationCollection\Core\Factory\BaseEmailDataFactory $factory
*/
public function __construct(MailerInterface $mailer, BaseEmailDataFactory $factory)

public function __construct(MailerInterface $mailer, DefaultProvider $emailDataProvider)
{
$this->mailer = $mailer;
$this->factory = $factory;
$this->emailDataProvider = $emailDataProvider;
}

/**
* {@inheritdoc}
*/
public function act(InformationCollected $event): void
{
$emailData = $this->factory->build($event);
$emailData = $this->emailDataProvider->provide($event);

try {
$this->mailer->createAndSendMessage($emailData);
$this->mailer->sendEmail($emailData);
} catch (EmailNotSentException $e) {
$this->throwException($e);
}
Expand Down
21 changes: 7 additions & 14 deletions lib/Core/EmailDataProvider/AutoResponderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,14 @@

namespace Netgen\InformationCollection\Core\EmailDataProvider;

use Netgen\InformationCollection\API\Action\EmailDataProviderInterface;
use Netgen\InformationCollection\API\Value\Event\InformationCollected;
use Symfony\Component\Mime\Email;
use Netgen\InformationCollection\Core\Factory\AutoResponderDataFactory;

class AutoResponderProvider implements EmailDataProviderInterface
class AutoResponderProvider extends DefaultProvider
{
public function provide(InformationCollected $value): Email
{
$email = new Email();

$headers = $email->getHeaders();

$header = new Header
$headers->add('Content-Type', '');

return $email;
// could be replaced by pure service configuration
public function __construct(
AutoResponderDataFactory $emailDataFactory
) {
parent::__construct($emailDataFactory);
}
}
105 changes: 27 additions & 78 deletions lib/Core/EmailDataProvider/DefaultProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,97 +2,46 @@

namespace Netgen\InformationCollection\Core\EmailDataProvider;

use EzSystems\EzPlatformContentForms\Data\Content\FieldData;
use Netgen\InformationCollection\API\Action\EmailDataProviderInterface;
use Netgen\InformationCollection\API\Value\Event\InformationCollected;
use Netgen\InformationCollection\Core\Factory\EmailDataFactory;
use Symfony\Component\Mime\Email;
use eZ\Publish\Core\MVC\ConfigResolverInterface;
use Netgen\InformationCollection\Core\Action\EmailAction;
use function array_key_exists;
use eZ\Publish\API\Repository\Values\Content\Field;
use eZ\Publish\Core\FieldType\BinaryFile\Value as BinaryFile;
use eZ\Publish\Core\Helper\FieldHelper;
use eZ\Publish\Core\Helper\TranslationHelper;
use Netgen\InformationCollection\API\Value\DataTransfer\EmailContent;
use Netgen\InformationCollection\API\Constants;
use Netgen\InformationCollection\API\ConfigurationConstants;
use Netgen\InformationCollection\API\Exception\MissingEmailBlockException;
use Netgen\InformationCollection\API\Exception\MissingValueException;
use Netgen\InformationCollection\API\Value\DataTransfer\TemplateContent;
use function trim;
use Twig\Environment;

class DefaultProvider implements EmailDataProviderInterface
{
/**
* @var array
*/
protected $configResolver;
protected $emailDataFactory;

/**
* @var \eZ\Publish\Core\Helper\TranslationHelper
*/
protected $translationHelper;

/**
* @var \eZ\Publish\Core\Helper\FieldHelper
*/
protected $fieldHelper;

/**
* @var \Twig\Environment
*/
protected $twig;

/**
* EmailDataFactory constructor.
*
* @param array $config
* @param \eZ\Publish\Core\Helper\TranslationHelper $translationHelper
* @param \eZ\Publish\Core\Helper\FieldHelper $fieldHelper
* @param \Twig\Environment $twig
*/
public function __construct(
ConfigResolverInterface $configResolver,
TranslationHelper $translationHelper,
FieldHelper $fieldHelper,
Environment $twig
EmailDataFactory $emailDataFactory
) {
$this->configResolver = $configResolver;
$this->config = $this->configResolver->getParameter('action_config', 'netgen_information_collection')[EmailAction::$defaultName];
$this->translationHelper = $translationHelper;
$this->fieldHelper = $fieldHelper;
$this->twig = $twig;
$this->emailDataFactory = $emailDataFactory;
}

/**
* Factory method.
*
* @param InformationCollected $value
*
* @return EmailContent
*/
public function build(InformationCollected $value): EmailContent
public function provide(InformationCollected $value): Email
{
$contentType = $value->getContentType();

$template = $this->resolveTemplate($contentType->identifier);

$templateWrapper = $this->twig->load($template);
$data = new TemplateContent($value, $templateWrapper);

$body = $this->resolveBody($data);

return new EmailContent(
$this->resolveEmail($data, Constants::FIELD_RECIPIENT),
$this->resolveEmail($data, Constants::FIELD_SENDER),
$this->resolve($data, Constants::FIELD_SUBJECT),
$body,
$this->resolveAttachments($contentType->identifier, $value->getInformationCollectionStruct()->getFieldsData())
$emailContent = $this->emailDataFactory->build($value);

$email = (new Email())
->from(...$emailContent->getSender())
->to(...$emailContent->getRecipients())
->subject($emailContent->getSubject())
->html($emailContent->getBody())
->text($emailContent->getBody());

array_map(
function (FieldData $fieldData) use ($email) {
$binaryFileValue = $fieldData->value;

$email->attachFromPath(
$binaryFileValue->inputUri,
$binaryFileValue->fileName,
$binaryFileValue->mimeType
);
},
$emailContent->getAttachments()
);
}

public function provide(InformationCollected $value): Email
{
return new Email();
return $email;
}
}
Loading