rtgx

Femanager: Použitie Signal Slot-u (hook)

Typo3 6.2, Femanager 1.5.0

Zadanie

V EXT femanager (registrácia frontend užívateľov) potrebujeme, aby sa do databázy okrem položiek first_name a last_name ukladala aj položka name a to spojením: name = first_name + ' ' + last_name.

Riešenie

Vytvoríme nový mini-extension, ktorý s použitím Femanager Slot/Signal "createActionBeforePersist" ošetrí zadanie.

ext_localconf.php

if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}

$signalSlotDispatcher = t3lib_div::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
$signalSlotDispatcher->connect(
'In2\Femanager\Controller\NewController',
'createActionBeforePersist',
'Magnetica\Femanagersignalslot\Utility\BeforePersist',
'update',
FALSE
);

Classes/Utility/BeforePersist.php

namespace Magnetica\Femanagersignalslot\Utility;

class BeforePersist {

/**
* Update FE user data before save into DB
*
* @param \In2\Femanager\Domain\Model\User $user
* @param \In2\Femanager\Controller\NewController $pObj
* @return void
*/
public function update($user, $pObj) {

$user->setName($user->getFirstName().' '.$user->getLastName());
}
}