Skip to content

Commit

Permalink
Merge pull request #6 from h3nn3s/typo3-v12
Browse files Browse the repository at this point in the history
Update for TYPO3 v12
  • Loading branch information
georgringer authored Sep 13, 2023
2 parents de96030 + 5fc95be commit 8664623
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 159 deletions.
2 changes: 1 addition & 1 deletion Classes/ApiWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* of the License, or any later version.
*/

use SendinBlue\Client\Configuration;
use Brevo\Client\Configuration;
use StudioMitte\Sendinblue\Configuration as ExtensionConfiguration;

/**
Expand Down
2 changes: 1 addition & 1 deletion Classes/Command/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* of the License, or any later version.
*/

use SendinBlue\Client\Api\ContactsApi;
use Brevo\Client\Api\ContactsApi;
use StudioMitte\Sendinblue\ApiWrapper;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand Down
52 changes: 33 additions & 19 deletions Classes/Finishers/SendinblueFinisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use SendinBlue\Client\Api\ContactsApi;
use SendinBlue\Client\Model\CreateContact;
use SendinBlue\Client\Model\CreateDoiContact;
use Brevo\Client\Api\ContactsApi;
use Brevo\Client\Model\CreateContact;
use Brevo\Client\Model\CreateDoiContact;
use StudioMitte\Sendinblue\ApiWrapper;
use StudioMitte\Sendinblue\Configuration;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -30,36 +30,33 @@ class SendinblueFinisher extends AbstractFinisher implements LoggerAwareInterfac
use LoggerAwareTrait;

/** @var Configuration */
protected $extensionConfiguration;
protected Configuration $extensionConfiguration;

public function __construct(string $finisherIdentifier = '')
{
parent::__construct($finisherIdentifier);
$this->extensionConfiguration = new Configuration();
}

protected function executeInternal()
protected function executeInternal(): void
{
if (!$this->newsletterSubscriptionIsEnabled()) {
$this->finisherContext->getFinisherVariableProvider()->add(
'sendinblue',
'subsribed',
0
);
return null;
$this->setFinisherSubscribedVariable(0);
return;
}

$this->addEntryToSendInBlue();
$this->addEntryToSendInBlue() ? $this->setFinisherSubscribedVariable(1) : $this->setFinisherSubscribedVariable(0);
}

protected function setFinisherSubscribedVariable(int $returnValue): void
{
$this->finisherContext->getFinisherVariableProvider()->add(
'sendinblue',
'data.subscribed',
1
$returnValue
);

return null;
}

protected function addEntryToSendInBlue(): void
protected function addEntryToSendInBlue(): bool
{
try {
$apiInstance = $this->getApi();
Expand All @@ -81,9 +78,11 @@ protected function addEntryToSendInBlue(): void
->setAttributes($this->getAttributes());
$apiInstance->createContact($createContact);
}
return true;
} catch (\Exception $exception) {
// todo: should we forward it to the user?
$this->logger->error($exception->getMessage());
return false;
}
}

Expand All @@ -96,9 +95,18 @@ protected function getDoiTemplateId(): int
return $this->extensionConfiguration->getDoiTemplateId();
}

protected function getDoiRedirectPageId(): int
{
$doiRedirectPageId = (int)$this->parseOption('doiRedirectPageId');
if ($doiRedirectPageId) {
return $doiRedirectPageId;
}
return $this->extensionConfiguration->getDoiRedirectPageId();
}

protected function newsletterSubscriptionIsEnabled(): bool
{
return (bool)$this->parseOption('enabled');
return $this->isEnabled();
}

protected function getEnrichedListIds(): array
Expand Down Expand Up @@ -142,13 +150,19 @@ protected function getAttributes(): object
if ($trackingAttribute = $this->extensionConfiguration->getAttributeTracking()) {
$attributes[$trackingAttribute] = $this->parseOption('tracking');
}

// additional attribute mappings
$additionalAttributes = $this->parseOption('additionalAttributes');
foreach ($additionalAttributes as $key => $value) {
$attributes[$key] = $value;
}
return (object)$attributes;
}

protected function getRedirectionUrl(): string
{
$typolinkConfiguration = [
'parameter' => $this->extensionConfiguration->getDoiRedirectPageId(),
'parameter' => $this->getDoiRedirectPageId(),
'forceAbsoluteUrl' => true,
];
return $this->getTypoScriptFrontendController()->cObj->typoLink_URL($typolinkConfiguration);
Expand Down
33 changes: 26 additions & 7 deletions Classes/Report/IntegrationReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
* of the License, or any later version.
*/

use SendinBlue\Client\Api\AccountApi;
use SendinBlue\Client\Api\ContactsApi;
use SendinBlue\Client\Api\TransactionalEmailsApi;
use SendinBlue\Client\ApiException;
use SendinBlue\Client\Model\GetAccount;
use Brevo\Client\Api\AccountApi;
use Brevo\Client\Api\ContactsApi;
use Brevo\Client\Api\TransactionalEmailsApi;
use Brevo\Client\ApiException;
use Brevo\Client\Model\GetAccount;
use StudioMitte\Sendinblue\ApiWrapper;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Exception\InvalidExtensionNameException;
Expand All @@ -36,11 +36,10 @@ class IntegrationReport implements ReportInterface
* @throws ApiException
* @throws InvalidExtensionNameException
*/
public function getReport()
public function getReport(): string
{
// Rendering of the output via fluid
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->getRequest()->setControllerExtensionName('Sendinblue');
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
'EXT:sendinblue/Resources/Private/Templates/IntegrationReport.html'
));
Expand Down Expand Up @@ -91,4 +90,24 @@ protected function getAccountInformation(): GetAccount
$api = new AccountApi(null, ApiWrapper::getConfig());
return $api->getAccount();
}

public function getIdentifier(): string
{
return 'general';
}

public function getTitle(): string
{
return 'LLL:EXT:sendinblue/Resources/Private/Language/locallang_report.xlf:report.title';
}

public function getDescription(): string
{
return 'LLL:EXT:sendinblue/Resources/Private/Language/locallang_report.xlf:report.description';
}

public function getIconIdentifier(): string
{
return 'module-reports';
}
}
4 changes: 4 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ services:
- name: 'console.command'
command: 'sendinblue:test'
schedulable: false

StudioMitte\Sendinblue\Report\IntegrationReport:
tags:
- name: reports.report
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@ TYPO3:
Form:
prototypes:
standard:
formEditor:
translationFiles:
1483353712: 'EXT:sendinblue/Resources/Private/Language/Form.xlf'
formElementsDefinition:
Form:
formEditor:
editors:
900:
# Extend finisher drop down
selectOptions:
35:
1483353712:
value: 'Sendinblue'
label: 'finisher.Sendinblue.label'
propertyCollections:
finishers:
# add finisher fields
25:
1483353712:
identifier: 'Sendinblue'
editors:
__inheritances:
10: 'TYPO3.CMS.Form.mixins.formElementMixins.BaseCollectionEditorsMixin'
100:
identifier: header
label: 'finisher.Sendinblue.label'
templateName: 'Inspector-CollectionElementHeaderEditor'
110:
identifier: 'enabled'
templateName: 'Inspector-TextEditor'
Expand All @@ -48,7 +50,6 @@ TYPO3:
propertyPath: 'options.firstName'
enableFormelementSelectionButton: true
propertyValidators:
10: 'NotEmpty'
20: 'FormElementIdentifierWithinCurlyBracesInclusive'
131:
identifier: 'lastName'
Expand All @@ -57,7 +58,6 @@ TYPO3:
propertyPath: 'options.lastName'
enableFormelementSelectionButton: true
propertyValidators:
10: 'NotEmpty'
20: 'FormElementIdentifierWithinCurlyBracesInclusive'
135:
identifier: 'additionalListIds'
Expand All @@ -72,11 +72,15 @@ TYPO3:
templateName: 'Inspector-TextEditor'
label: 'finisher.Sendinblue.field.tracking'
propertyPath: 'options.tracking'
9999:
identifier: 'removeButton'
templateName: 'Inspector-RemoveElementEditor'
finishersDefinition:
Sendinblue:
implementationClassName: 'StudioMitte\Sendinblue\Finishers\SendinblueFinisher'
formEditor:
iconIdentifier: 'form-finisher'
label: 'Sendinblue Finisher'
label: 'finisher.Sendinblue.label'
predefinedDefaults:
options:
enabled: ''
Expand All @@ -85,7 +89,7 @@ TYPO3:
email: ''
additionalListIds: ''
tracking: 'trackingvalue'
# displayed when overriding finisher settings
# displayed when overriding finisher settings
FormEngine:
label: 'finisher.Sendinblue.label'
elements:
Expand All @@ -104,7 +108,7 @@ TYPO3:
firstName:
label: 'finisher.Sendinblue.field.firstName'
config:
type: 'text'
type: 'text'
lastName:
label: 'finisher.Sendinblue.field.lastName'
config:
Expand All @@ -113,8 +117,3 @@ TYPO3:
label: 'finisher.Sendinblue.field.additionalListIds'
config:
type: 'text'
formEditor:
translationFile:
91818: 'EXT:sendinblue/Resources/Private/Language/Form.xlf'
translationFiles:
91818: 'EXT:sendinblue/Resources/Private/Language/Form.xlf'
8 changes: 0 additions & 8 deletions Configuration/Yaml/SendinblueFrontend.yaml

This file was deleted.

24 changes: 12 additions & 12 deletions Resources/Private/Example/sendinblue-example.form.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ label: sendinblue
prototypeName: standard
finishers:
-
options:
renderingOptions:
enabled: '{checkbox-1}'
options:
firstName: '{text-1}'
lastName: '{text-3}'
email: '{text-2}'
tracking: trackingvalue
additionalListIds: '{multicheckbox-1}'
additionalAttributes:
salutation: '{salutation}'

# override global settings
# doiTemplateId: '14'
Expand All @@ -33,29 +36,26 @@ renderables:
identifier: page-1
label: Step
renderables:
-
properties:
options:
'1': 'Mr.'
'2': 'Mrs.'
type: SingleSelect
identifier: salutation
label: Salutation
-
defaultValue: ''
type: Text
identifier: text-1
label: Vorname
properties:
elementDescription: ''
fluidAdditionalAttributes:
required: required
validators:
-
identifier: NotEmpty
-
defaultValue: ''
type: Text
identifier: text-3
label: Nachname
properties:
fluidAdditionalAttributes:
required: required
validators:
-
identifier: NotEmpty
-
defaultValue: ''
type: Text
Expand Down
7 changes: 5 additions & 2 deletions Resources/Private/Language/locallang_report.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<trans-unit id="contacts" resname="contacts">
<source>Contacts</source>
</trans-unit>
<trans-unit id="contacts.list" resname="contacts.list">
<trans-unit id="contacts.lists" resname="contacts.lists">
<source>Lists</source>
</trans-unit>
<trans-unit id="contacts.attribute.id" resname="contacts.attribute.id">
Expand All @@ -26,6 +26,9 @@
<trans-unit id="contacts.attribute.totalSubscriber" resname="contacts.attribute.totalSubscriber">
<source>Total Subscriber</source>
</trans-unit>
<trans-unit id="contacts.attribute.uniqueSubscribers" resname="contacts.attribute.uniqueSubscribers">
<source>Unique Subscriber</source>
</trans-unit>
<trans-unit id="contacts.attribute.totalBlacklisted" resname="contacts.attribute.totalBlacklisted">
<source>Total Blacklisted</source>
</trans-unit>
Expand Down Expand Up @@ -73,4 +76,4 @@
</trans-unit>
</body>
</file>
</xliff>
</xliff>
Loading

0 comments on commit 8664623

Please sign in to comment.