Reputation: 527
TYPO3 10, Powermail 8.4
After successful double opt-in validation via Powermail, I want to send the mail data to an external API.
In \In2code\Powermail\Controller\FormController
there is a signal AfterPersist
what I could use.
In my extension I added in ext_localconf.php
:
$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
$signalSlotDispatcher->connect(
\In2code\Powermail\Controller\FormController::class,
'AfterPersist',
\MyVendor\MyForms\EventListener\SendToApi::class,
'run'
);
My class looks like this, for the moment:
namespace MyVendor\MyForms\EventListener;
use Symfony\Component\Mime\Address;
use TYPO3\CMS\Core\Mail\MailMessage;
class SendToApi {
public function run() {
$mail = GeneralUtility::makeInstance(MailMessage::class);
$mail
->from(new Address('[email protected]', 'DEV Server'))
->to(new Address('[email protected]', 'Webmaster'))
->subject('Slot test')
->text('Here is the message')
->html('<p>Here is the message</p>')
->send();
}
}
My questions:
Upvotes: 1
Views: 166
Reputation: 1172
In Powermail 8.4.x the signalslot is still implemented. From Powermail version 12 onwards, event dispatching must be used.
The SignalSlotDispatcher is marked as deprecated as of TYPO3 11 and will be removed in TYPO3 12.
If you do not use XDebug for debugging you could do a simple die in your sendToApi-method:
die("Is called")
Then you should get a whitescreen with that text.
EDIT:
The reason why your function is not called, is because you use the wrong name for the Signal.
A look in the Powermail FormController shows:
$this->signalDispatch(__CLASS__, __FUNCTION__ . 'AfterPersist', [$mail, $hash, $this]);
So the signalname is concatenated from the name of the function and the name of the signal.
So you must implement it like that:
$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
$signalSlotDispatcher->connect(
\In2code\Powermail\Controller\FormController::class,
'optinConfirmActionAfterPersist',
\MyVendor\MyForms\EventListener\SendToApi::class,
'run'
);
Upvotes: 2