dmk/mkoptin

MK Optin Extension

Installs: 57

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 13

Forks: 0

Open Issues: 0

Type:typo3-cms-extension

v10.0.0 2021-12-08 14:53 UTC

This package is auto-updated.

Last update: 2024-11-08 14:24:36 UTC


README

TYPO3 compatibility Latest Stable Version Total Downloads Build Status Code Coverage License

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.

Installation

Install TYPO3 via composer.
From project root you need to run

composer require dmk/mkoptin

Start a new opt-in process

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);
    }
}

register opt-in validation success event listeners

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
    }
}

Add opt-in information to TCA

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',
            ],
        ],
    ]
];

OptIn State Element

WARNING: Currently the field in the data record must always be email!

Templates

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
        }
    }
}

@TODOs

  • Implement table email field configuration