CollectAllowedTablesEvent

This event is triggered when the extension collects the allowed tables to react on. This is typically the case when it hooks into TYPO3\CMS\Core\DataHandling\DataHandler to check whether MFA (currently TOTP) may be enabled or disabled after editing a record and trying to save it.

If you want to use MFA for your own extension, you can listen to this event and add your own table(s) to the list of allowed tables (by default fe_users).

Registering a listener

Open your extension's Configuration/Services.yaml file and append:

YourVendor\YourExtension\EventListener\MfaFrontendListener:
  tags:
    - name: event.listener
      identifier: 'yourVendor/yourExtension'
      method: 'collectAllowedTables'
      event: Causal\MfaFrontend\Event\CollectAllowedTablesEvent

Create Classes/EventListener/MfaFrontendListener.php to read:

<?php
declare(strict_types=1);

namespace YourVendor\YourExtension\EventListener;

use Causal\MfaFrontend\Event\CollectAllowedTablesEvent;

class MfaFrontendListener
{
    public function collectAllowedTables(CollectAllowedTablesEvent $event): void
    {
        $tables = $event->getTables();
        $tables[] = 'tx_yourextension_domain_model_yourmodel';
        $event->setTables($tables);
    }
}

Extend your TCA

You need to add a new field to your TCA to store the MFA secret. The field must be named mfa.

Edit ext_tables.sql and add the field to your table:

CREATE TABLE tx_yourextension_domain_model_yourmodel (
    ...
    mfa mediumblob
);

Create Configuration/TCA/Overrides/tx_yourextension_domain_model_yourmodel.php to add the mfa field as passthrough and two virtual fields for the setup:

<?php
defined('TYPO3') || die();

$tempColumns = [
    'tx_mfafrontend_enable' => [
        'exclude' => false,
        'label' => 'LLL:EXT:mfa_frontend/Resources/Private/Language/locallang_db.xlf:fe_users.tx_mfafrontend_enable',
        'config' => [
            'type' => 'none',
            'renderType' => 'MfaFrontendEnable',
        ]
    ],
    'tx_mfafrontend_secret' => [
        'exclude' => false,
        'label' => 'LLL:EXT:mfa_frontend/Resources/Private/Language/locallang_db.xlf:fe_users.tx_mfafrontend_secret',
        'config' => [
            'type' => 'none',
            'renderType' => 'MfaFrontendTotp',
        ]
    ],
    'mfa' => [
        'config' => [
            'type' => 'passthrough',
        ],
    ],
];

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
    'tx_yourextension_domain_model_yourmodel',
    $tempColumns
);

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
    'tx_yourextension_domain_model_yourmodel',
    'tx_mfafrontend_enable,tx_mfafrontend_secret',
    '',
    'after:password' // Add the 2FA after our custom field "password"
);