Skip to content

Commit

Permalink
Merge pull request #4 from BeerOnTheBeach/main
Browse files Browse the repository at this point in the history
add 12LTS compatibility, drop 11LTS compatibility
  • Loading branch information
jpmschuler authored Sep 6, 2024
2 parents 324df13 + 305e072 commit 4764c6d
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 8,628 deletions.
3 changes: 0 additions & 3 deletions Classes/DataProcessor/SubmissionLimitDataProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
use Jpmschuler\PowermailLimits\Domain\Model\FormWithSubmissionLimit;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

/**
* Class DoSomethingDataProcessor
*/
class SubmissionLimitDataProcessor extends AbstractDataProcessor
{
/**
Expand Down
33 changes: 33 additions & 0 deletions Classes/EventListener/AddBodyPrefixHeaderAndTextToView.php
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);
}
}
32 changes: 32 additions & 0 deletions Classes/EventListener/AddSubjectPrefixToMail.php
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);
}
}
53 changes: 53 additions & 0 deletions Classes/Service/PowerMailLimitsService.php
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);
}
}
20 changes: 20 additions & 0 deletions Configuration/Services.yaml
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'

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

defined('TYPO3') || die();

(static function () {
Expand Down Expand Up @@ -46,6 +48,6 @@

];

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tx_powermail_domain_model_form', $formsTca);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToAllPalettesOfField('tx_powermail_domain_model_form', 'title', 'submissionlimit,haswaitlist,showsubmissionsfullpercentage', 'after:title');
ExtensionManagementUtility::addTCAcolumns('tx_powermail_domain_model_form', $formsTca);
ExtensionManagementUtility::addFieldsToAllPalettesOfField('tx_powermail_domain_model_form', 'title', 'submissionlimit,haswaitlist,showsubmissionsfullpercentage', 'after:title');
})();
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
[![Latest Packagist version](https://shields.io/packagist/v/jpmschuler/powermail-limits?label=Packagist&logo=packagist&logoColor=white)](https://packagist.org/packages/jpmschuler/powermail-limits)
![Total downloads](https://typo3-badges.dev/badge/powermail_limits/downloads/shields.svg)

![Supported TYPO3 versions](https://shields.io/endpoint?label=typo3&url=https://typo3-badges.dev/badge/powermail_limits/typo3/shields)
![Supported PHP versions](https://shields.io/packagist/php-v/jpmschuler/powermail-limits?logo=php)
![Supported TYPO3 versions](https://shields.io/endpoint?label=typo3&url=https://typo3-badges.dev/badge/powermail/typo3/shields)
[![Current CI health](https://github.com/jpmschuler/TYPO3-powermail-limits/actions/workflows/ci.yml/badge.svg)](https://github.com/jpmschuler/TYPO3-powermail-limits/actions/workflows/ci.yml)


Expand All @@ -15,9 +14,9 @@ This extension allows you to set a submission limit for a TYPO3 EXT:powermail fo

# Compatibility

- TYPO3: ^11
- PHP: ^7.4
- EXT:powermail ^10
- TYPO3: ^12
- PHP: ^8.0 (tested with 8.2)
- EXT:powermail ^12.4.0

# Installation

Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"in2code\/powermail": "^10.0.0",
"typo3\/cms-core": "^11.5.26",
"typo3\/cms-frontend": "^11.5.26"
"php": "^8.0 || ^8.2",
"in2code\/powermail": "^12.4.0",
"typo3\/cms-core": "^11.5.26 || ^12.4",
"typo3\/cms-frontend": "^11.5.26 || ^12.4"
},
"require-dev": {
"ergebnis\/composer-normalize": "^2.19.0",
Expand Down Expand Up @@ -99,7 +99,7 @@
"lint:php-cs-fixer": "php-cs-fixer fix",
"lint:php-cs-fixer:dry-run": "php-cs-fixer fix --dry-run --using-cache=no --diff",
"lint:php-cs-fixer:dry-run:onlyerrors": "php-cs-fixer fix --dry-run --using-cache=no --diff > \/dev\/null",
"lint:php:onlyerrors": "find *.php Classes -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l > \/dev\/null",
"lint:php:onlyerrors": "find *.php Classes -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l > \\\\/dev\\\\/null",
"lint:phpcbf": "phpcbf Classes",
"lint:phpcs": "@lint:phpcbf",
"lint:phpcs:dry-run": "phpcs Classes",
Expand Down Expand Up @@ -128,12 +128,12 @@
"rm rector.php"
],
"rector": [
"rector process --config=rector.php . ",
"rector process --config=rectorphp ",
"@lint:php-cs-fixer"
],
"rector:dry-run": "rector process --config=rector.php --dry-run -- .",
"rector:dry-run:ci": "rector process --config=rector.php --dry-run --output-format json -- . > report.rector.json",
"rector:force": "rector process .",
"rector:dry-run": "rector process --config=rectorphp --dry-run -- ",
"rector:dry-run:ci": "rector process --config=rectorphp --dry-run --output-format json -- > report.rector.json",
"rector:force": "rector process ",
"test": [
"@lint:php-cs-fixer"
],
Expand Down
Loading

0 comments on commit 4764c6d

Please sign in to comment.