diff --git a/Classes/Controller/NewsletterController.php b/Classes/Controller/NewsletterController.php index f06eaba..beca92d 100644 --- a/Classes/Controller/NewsletterController.php +++ b/Classes/Controller/NewsletterController.php @@ -11,6 +11,7 @@ use In2code\Luxletter\Domain\Service\PreviewUrlService; use In2code\Luxletter\Domain\Service\QueueService; use In2code\Luxletter\Domain\Service\ReceiverAnalysisService; +use In2code\Luxletter\Events\AfterTestMailButtonClickedEvent; use In2code\Luxletter\Exception\AuthenticationFailedException; use In2code\Luxletter\Mail\TestMail; use In2code\Luxletter\Utility\BackendUserUtility; @@ -225,16 +226,43 @@ public function testMailAjax(ServerRequestInterface $request): ResponseInterface if (BackendUserUtility::isBackendUserAuthenticated() === false) { throw new AuthenticationFailedException('You are not authenticated to send mails', 1560872725); } - $testMail = GeneralUtility::makeInstance(TestMail::class); - $status = $testMail->preflight( - $request->getQueryParams()['origin'], - $request->getQueryParams()['layout'], - (int)$request->getQueryParams()['configuration'], - $request->getQueryParams()['subject'], - $request->getQueryParams()['email'] - ); + $status = null; + + /** + * This event can be used for sending the Testemail with external logic + * @see Documentation/Tech/Events.md + */ + /** @var AfterTestMailButtonClickedEvent $event */ + $event = GeneralUtility::makeInstance(AfterTestMailButtonClickedEvent::class); + $event->setRequest($request); + $this->eventDispatcher->dispatch($event); + + if (!$event->isTestMailIsSendExternal()) { + $testMail = GeneralUtility::makeInstance(TestMail::class); + $status = $testMail->preflight( + $request->getQueryParams()['origin'], + $request->getQueryParams()['layout'], + (int)$request->getQueryParams()['configuration'], + $request->getQueryParams()['subject'], + $request->getQueryParams()['email'] + ); + } + $event->setTestMailIsSendExternal(true); $response = ObjectUtility::getJsonResponse(); - $response->getBody()->write(json_encode(['status' => $status])); + $responseData = [ + 'status' => $status ?? $event->getStatus(), + ]; + if ($event->isTestMailIsSendExternal()){ + $responseData = array_merge( + $responseData, + [ + 'statusTitle' => $event->getStatusTitle(), + 'statusMessage' => $event->getStatusMessage(), + 'statusSeverity' => $event->getStatusSeverity(), + ] + ); + } + $response->getBody()->write(json_encode($responseData, JSON_THROW_ON_ERROR)); return $response; } @@ -261,8 +289,10 @@ public function receiverDetailAjax(ServerRequestInterface $request): ResponseInt $standaloneView->assignMultiple([ 'user' => $user, 'visitor' => $visitorRepository->findOneByFrontenduser($user), - 'logs' => $logRepository->findByUser($user), ]); + if ($user !== null) { + $standaloneView->assign('logs', $logRepository->findByUser($user)); + } $response = ObjectUtility::getJsonResponse(); $response->getBody()->write(json_encode( ['html' => $standaloneView->render()] diff --git a/Classes/Events/AfterTestMailButtonClickedEvent.php b/Classes/Events/AfterTestMailButtonClickedEvent.php new file mode 100644 index 0000000..b489ca8 --- /dev/null +++ b/Classes/Events/AfterTestMailButtonClickedEvent.php @@ -0,0 +1,85 @@ +testMailIsSendExternal; + } + + public function setTestMailIsSendExternal(bool $testMailIsSendExternal): void + { + $this->testMailIsSendExternal = $testMailIsSendExternal; + } + + public function getStatus(): bool + { + return $this->status; + } + + public function setStatus(bool $status): void + { + $this->status = $status; + } + + public function getRequest(): ServerRequestInterface + { + return $this->request; + } + + public function setRequest(ServerRequestInterface $request): void + { + $this->request = $request; + } + + public function getStatusTitle(): string + { + return $this->statusTitle; + } + + public function setStatusTitle(string $statusTitle): void + { + $this->statusTitle = $statusTitle; + } + + public function getStatusMessage(): string + { + return $this->statusMessage; + } + + public function setStatusMessage(string $statusMessage): void + { + $this->statusMessage = $statusMessage; + } + + public function getStatusSeverity(): string + { + return $this->statusSeverity; + } + + public function setStatusSeverity(string $statusSeverity): void + { + $this->statusSeverity = $statusSeverity; + } +} diff --git a/Documentation/Tech/Events.md b/Documentation/Tech/Events.md new file mode 100644 index 0000000..0bb725e --- /dev/null +++ b/Documentation/Tech/Events.md @@ -0,0 +1,43 @@ + + +# Luxletter - Email marketing in TYPO3. Send newsletters the easy way. + +## Events + +There are many events that can be used to extend Luxletter. +This documentation is under construction and not all events are documented yet. + +### AfterTestMailButtonClickedEvent + +This event can be used to deactivate the internal sending of test emails and implement your own logic, e.g. sending test newsletters via a separate queue. + +To deactivate the internal logic, the `$testMailIsSendExternal` property of the event must be set to true. +If the general status `$status` is set to `false`, no message is shown. +If the general status `$status` is set to `true`, a message with the properties `$statusTitle`, `$statusMessage` and `$statusSeverity` is shown. +The values for `$statusSeverity` can be `AfterTestMailButtonClickedEvent::STATUS_SEVERITY_SUCCESS`, `AfterTestMailButtonClickedEvent::STATUS_SEVERITY_WARNING` and `AfterTestMailButtonClickedEvent::STATUS_SEVERITY_ERROR`, the default value is `AfterTestMailButtonClickedEvent::STATUS_SEVERITY_ERROR`. + +The `$request` property is available in the event, from which all necessary data can be obtained to send the test e-mail. + +Sample Eventlistener: + +``` +setTestMailIsSendExternal(true); + // ... handle email sending + $event->setStatus(true); + $event->setStatusSeverity(AfterTestMailButtonClickedEvent::STATUS_SEVERITY_SUCCESS); + $event->setStatusTitle('Success'); + $event->setStatusMessage('The test email is successfully added to the queue'); + } +} +``` diff --git a/Resources/Private/Build/JavaScript/Module.js b/Resources/Private/Build/JavaScript/Module.js index 2fd8131..7c849d2 100644 --- a/Resources/Private/Build/JavaScript/Module.js +++ b/Resources/Private/Build/JavaScript/Module.js @@ -265,13 +265,19 @@ define(['jquery'], function($) { */ this.testMailListenerCallback = function(response) { const messageElement = document.querySelector('[data-luxletter-testmail="message"]'); - if (messageElement !== null && response.status === true) { + if (messageElement !== null && response.statusSeverity === undefined && response.status === true) { showElement(messageElement); const counterElement = messageElement.querySelector('p>span'); let counter = parseInt(counterElement.innerHTML); counter++; counterElement.innerHTML = counter.toString(); + } else if(messageElement !== null && response.statusSeverity !== '' && response.status === true) { + messageElement.classList.remove('alert-success'); + messageElement.classList.add(response.statusSeverity); + messageElement.querySelector('.alert-heading').innerHTML = response.statusTitle; + messageElement.querySelector('p').innerHTML = response.statusMessage; + showElement(messageElement); } }; diff --git a/Resources/Public/JavaScript/Luxletter/Module.min.js b/Resources/Public/JavaScript/Luxletter/Module.min.js index 4138281..b0f1601 100644 --- a/Resources/Public/JavaScript/Luxletter/Module.min.js +++ b/Resources/Public/JavaScript/Luxletter/Module.min.js @@ -1 +1 @@ -define(["jquery"],function(e){"use strict";function t(e){var l=this,i=!1,r=!1,t=(this.initialize=function(){t(),n(),o(),d(),s(),v(),f()},function(){for(var r=document.querySelectorAll(".wizardform > fieldset"),e=document.querySelectorAll("[data-wizardform-gotostep]"),n=document.querySelectorAll(".wizard > a"),t=1;tspan"),t=parseInt(e.innerHTML),e.innerHTML=(++t).toString())},this.userDetailListenerCallback=function(e){var t=document.getElementById("luxletter-newsletter-receiver-container");null!==t&&(t.innerHTML=e.html)},function(e,t,r){var n;void 0!==e&&""!==e?((n=new XMLHttpRequest).onreadystatechange=function(){4===this.readyState&&200===this.status&&null!==r&&l[r](JSON.parse(this.responseText))},n.open("POST",g(e,t),!0),n.send()):console.log("No ajax URI given!")}),w=function(){if(x()&&y())for(var e=document.querySelectorAll("[data-luxletter-wizardstatus]"),t=0;t fieldset"),e=document.querySelectorAll("[data-wizardform-gotostep]"),l=document.querySelectorAll(".wizard > a"),t=1;tspan"),r=parseInt(t.innerHTML),t.innerHTML=(++r).toString()):null!==l&&""!==e.statusSeverity&&!0===e.status&&(l.classList.remove("alert-success"),l.classList.add(e.statusSeverity),l.querySelector(".alert-heading").innerHTML=e.statusTitle,l.querySelector("p").innerHTML=e.statusMessage,h(l))},this.userDetailListenerCallback=function(e){var t=document.getElementById("luxletter-newsletter-receiver-container");null!==t&&(t.innerHTML=e.html)},function(e,t,r){var l;void 0!==e&&""!==e?((l=new XMLHttpRequest).onreadystatechange=function(){4===this.readyState&&200===this.status&&null!==r&&n[r](JSON.parse(this.responseText))},l.open("POST",x(e,t),!0),l.send()):console.log("No ajax URI given!")}),w=function(){if(y()&&g())for(var e=document.querySelectorAll("[data-luxletter-wizardstatus]"),t=0;t