AfterProfileMappedFromFrontendUserEvent
\FGTCLB\
hands a listener the profile the frontend user synchronisation has just mapped
from the data of a frontend user, before it is saved. A listener translates a
value of the source into one the profile offers, or derives a value from
others. What it sets on the profile and its contracts is saved with it.
When it is dispatched
Abstract dispatches the event, under the same conditions
as BeforeProfileMappedFromFrontendUserEvent:
academic:: once per frontend user, after the new profile was mapped and attached to the frontend user. Not when a listener skipped the frontend user, and not when the factory has no profile for it.createprofiles academic:: once per synchronised profile of the frontend user, after the profile was mapped. Not for a skipped profile.updateprofiles
It is step 4 of the run described in Taking part in the frontend user synchronisation. The profile is saved and announced with AfterProfileUpdateEvent afterwards.
What a listener reads and changes
| Method | What it does |
|---|---|
get | The mapped profile. The event has no setter: the listener changes the object, and the change is saved. |
get | The data the mapping used, with the values the listeners of
Before added. |
get |
Profile or
Profile. |
Example
A site's directory service delivers the gender as w, m or d, added
to the data as ldap. by the example of
BeforeProfileMappedFromFrontendUserEvent. The
listener translates it into the values the profile offers:
<?php
declare(strict_types=1);
namespace MyVendor\MySitepackage\EventListener;
use FGTCLB\AcademicPersons\Event\AfterProfileMappedFromFrontendUserEvent;
use TYPO3\CMS\Core\Attribute\AsEventListener;
final readonly class MapGender
{
private const GENDERS = ['w' => 'ms', 'm' => 'mr', 'd' => 'diverse'];
#[AsEventListener(identifier: 'my-sitepackage/map-gender')]
public function __invoke(AfterProfileMappedFromFrontendUserEvent $event): void
{
$source = (string)($event->getFrontendUserData()['ldap.gender'] ?? '');
$event->getProfile()->setGender(self::GENDERS[$source] ?? '');
}
}
A listener that sets the employee type of the imported contract from the frontend user data is described in Organisational unit and function type.
Rules and pitfalls
- A value the map writes is written on every run. A listener that changes it has to change it on every run as well, or the next run writes the mapped value again.
- The profile is not saved yet. Do not persist it from the listener, the factory saves it after all listeners ran.
- On update the event is dispatched once per profile, so a frontend user with two synchronised profiles reaches the listener twice.
Introduced in
- Feature: Events to add data to the synchronisation and adjust profiles introduced the event.