This TYPO3 extension provides an opt-in process via fluid mails.
What it does in short:
- Can be triggered to send an Opt-In-E-Mail
- Processes the verification via activation link in email.
- triggers a opt-in validation success event.
- Adds opt-in information to tca.
Install TYPO3 via composer.
From project root you need to run
composer require dmk/mkoptin
class MyAwesomeManager
{
private OptinManager $optinManager;
public function __construct(
OptinManager $optinManager
) {
$this->optinManager = $optinManager;
}
protected function handleOptIn(string $email): void
{
$optin = $this->optinManager->createOptinForEmail($email);
// opt in already done :)
if ($optin->isValidated()) {
// opt-in already performed, do your finalize stuff here
return;
}
// opt-in outstanding, send opt-in mail
// finalize stuff has to be performed by event listener after opt-in validation
$this->optinManager->sendValidationMailForOptin($optin);
}
}
Why we need this?
To do things after the email has been verified, such as activate the record or
send confirmation emails.
services:
DMK\MyAwesomeExtension\Event\EventListener\OptinValidationSuccessEventListener:
tags:
-
name: 'event.listener'
identifier: 'MyAwesomeOptinValidationSuccessEventListener'
event: DMK\Optin\Event\OptinValidationSuccessEvent
class OptinValidationSuccessEventListener
{
private MyAwesomeManager $manager;
public function __construct(
MyAwesomeManager $manager
) {
$this->manager = $manager;
}
public function __invoke(OptinValidationSuccessEvent $event): void
{
$this->manager->handleOptinValidation($event->getOptin());
}
}
class MyAwesomeManager
{
public function handleOptinValidation(Optin $optin): void
{
// opt-in performed, do your finalize stuff here
}
}
In order to output the opt-in information for a data record, the following TCA column must be added:
return [
'columns' => [
'optin' => [
'label' => 'LLL:EXT:mkoptin/Resources/Private/Language/locallang_db.xlf:tx_mkoptin_domain_model_optin',
'config' => [
'type' => 'user',
'renderType' => 'optInStateElement',
],
],
]
];
WARNING: Currently the field in the data record must always be email
!
plugin {
tx_mkoptin {
view {
templateRootPath = EXT:myawesomeextension/Resources/Private/Templates/Optin
partialRootPath = EXT:myawesomeextension/Resources/Private/Partials/Optin
layoutRootPath = EXT:myawesomeextension/Resources/Private/Layouts/Optin
}
}
}
- Implement table email field configuration