-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from BeerOnTheBeach/main
add 12LTS compatibility, drop 11LTS compatibility
- Loading branch information
Showing
11 changed files
with
165 additions
and
8,628 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
Classes/EventListener/AddBodyPrefixHeaderAndTextToView.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Jpmschuler\PowermailLimits\EventListener; | ||
|
||
use In2code\Powermail\Events\SendMailServiceCreateEmailBodyEvent; | ||
use Jpmschuler\PowermailLimits\Domain\Model\FormWithSubmissionLimit; | ||
use Jpmschuler\PowermailLimits\Service\PowerMailLimitsService; | ||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | ||
|
||
#[AsEventListener] | ||
final class AddBodyPrefixHeaderAndTextToView | ||
{ | ||
public function __construct( | ||
private readonly PowerMailLimitsService $powerMailLimitsService, | ||
) { | ||
} | ||
|
||
public function __invoke(SendMailServiceCreateEmailBodyEvent $event): void | ||
{ | ||
$originalService = $event->getSendMailService(); | ||
$standaloneView = $event->getStandaloneView(); | ||
$email = $event->getEmail(); | ||
|
||
$form = $originalService->getMail()->getForm(); | ||
|
||
if (!$form instanceof FormWithSubmissionLimit) { | ||
return; | ||
} | ||
|
||
$standaloneView = $this->powerMailLimitsService->getNewViewWithBodyPrefix($form, $standaloneView, $email); | ||
$event->setStandaloneView($standaloneView); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Jpmschuler\PowermailLimits\EventListener; | ||
|
||
use In2code\Powermail\Events\SendMailServicePrepareAndSendEvent; | ||
use Jpmschuler\PowermailLimits\Domain\Model\FormWithSubmissionLimit; | ||
use Jpmschuler\PowermailLimits\Service\PowerMailLimitsService; | ||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | ||
|
||
#[AsEventListener] | ||
final class AddSubjectPrefixToMail | ||
{ | ||
public function __construct( | ||
private readonly PowerMailLimitsService $powerMailLimitsService | ||
) { | ||
} | ||
|
||
public function __invoke(SendMailServicePrepareAndSendEvent $event): void | ||
{ | ||
$originalService = $event->getSendMailService(); | ||
$message = $event->getMailMessage(); | ||
|
||
$form = $originalService->getMail()->getForm(); | ||
|
||
if (!$form instanceof FormWithSubmissionLimit) { | ||
return; | ||
} | ||
|
||
$message = $this->powerMailLimitsService->getNewMailMessageWithSubjectPrefix($form, $message); | ||
$event->setMailMessage($message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Jpmschuler\PowermailLimits\Service; | ||
|
||
use Jpmschuler\PowermailLimits\Domain\Model\FormWithSubmissionLimit; | ||
use TYPO3\CMS\Core\Mail\MailMessage; | ||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; | ||
use TYPO3\CMS\Fluid\View\StandaloneView; | ||
|
||
class PowerMailLimitsService | ||
{ | ||
const EXTENSION_KEY = 'powermail_limits'; | ||
|
||
public function getNewMailMessageWithSubjectPrefix(FormWithSubmissionLimit $form, MailMessage $message): MailMessage | ||
{ | ||
$subjectPrefix = ''; | ||
|
||
if ($form->isNewSubmissionForWaitlistMailManipulation()) { | ||
$subjectPrefix = $this->getTranslation('mail.waitinglistsubmission.subjectprefix'); | ||
} elseif (!$form->isNewSubmissionValid()) { | ||
$subjectPrefix = $this->getTranslation('mail.invalidsubmission.subjectprefix'); | ||
} | ||
|
||
$subject = $subjectPrefix . $message->getSubject(); | ||
|
||
return $message->setSubject($subject); | ||
} | ||
|
||
public function getNewViewWithBodyPrefix(FormWithSubmissionLimit $form, StandaloneView $standaloneView, array $email): StandaloneView | ||
{ | ||
$bodyPrefixHeader = ''; | ||
$bodyPrefixText = ''; | ||
|
||
if ($form->isNewSubmissionForWaitlistMailManipulation()) { | ||
$bodyPrefixHeader = $this->getTranslation('mail.waitinglistsubmission.bodyprefix.header'); | ||
$bodyPrefixText = $this->getTranslation('mail.waitinglistsubmission.bodyprefix.text'); | ||
} elseif (!$form->isNewSubmissionValid()) { | ||
$bodyPrefixHeader = $this->getTranslation('mail.invalidsubmission.bodyprefix.header'); | ||
$bodyPrefixText = $this->getTranslation('mail.invalidsubmission.bodyprefix.text'); | ||
} | ||
|
||
$bodyPrefix = sprintf('<p><strong>%s</strong></p><p>%s</p><hr>', $bodyPrefixHeader, $bodyPrefixText); | ||
$email['rteBody'] = $bodyPrefix . $email['rteBody']; | ||
$standaloneView->assign('powermail_rte', $email['rteBody']); | ||
|
||
return $standaloneView; | ||
} | ||
|
||
private function getTranslation(string $key): ?string | ||
{ | ||
return LocalizationUtility::translate($key, self::EXTENSION_KEY); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
Jpmschuler\PowermailLimits\: | ||
resource: '../Classes/*' | ||
|
||
Jpmschuler\PowermailLimits\EventListener\AddBodyPrefixHeaderAndTextToView: | ||
tags: | ||
- name: event.listener | ||
identifier: 'addBodyAndPrefixHeaderAndTextToView' | ||
|
||
|
||
Jpmschuler\PowermailLimits\EventListener\AddSubjectPrefixToMail: | ||
tags: | ||
- name: event.listener | ||
identifier: 'addSubjectPrefixToMail' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.