Using SignalSlots (Hook pendant) to extend femanager¶
Introduction¶
SignalSlots (former Hooks) are the possibility for other developer to extend the runtime of a femanager process with their own code.
As an example let’s build an extension which sends username and email address of a new registered user to a defined email address.
Note: this is a little bit useless because there is already a setting in flexform to inform administrators and there is a setting in TypoScript to POST values to a third-party-software, but let’s use this case for an example.
SignalSlots List¶
Use a SignalSlot¶
Introduction¶
As described before, we want to send an email to a defined address every time when a new user is registered.
Creating an extension¶
femanagersignalslot/ext_emconf.php:
This file is important to install your new extension – write something like:
<?php
$EM_CONF[$_EXTKEY] = array(
'title' => 'femanagersignalslot',
'description' => 'signalslotexample for femanager',
'state' => 'alpha',
'version' => '0.0.1',
'constraints' => array(
'depends' => array(
'extbase' => '6.0.0-6.1.99',
'fluid' => '6.0.0-6.1.99',
'typo3' => '6.0.0-6.1.99',
'femanager' => '1.0.0-1.0.99',
),
'conflicts' => array(
),
'suggests' => array(
),
),
);
femanagersignalslot/ext_localconf.php:
This is an example how to use a signal from femanager – in this case we decided to use the signal “createActionBeforePersist” in class “In2codeFemanagerControllerNewController” and want to call a slot in class “In2codeFemanagersignalslotDomainServiceSendMailService” with methodname “send()”
<?php
$signalSlotDispatcher = t3lib_div::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
$signalSlotDispatcher->connect(
'In2code\Femanager\Controller\NewController',
'createActionBeforePersist',
'In2code\Femanagersignalslot\Domain\Service\SendMailService',
'send',
FALSE
);
femanagersignalslot/Classes/Domain/Service/SendMailService.php:
This is our main class which is called every time a new registration process was initiated.
<?php
namespace In2code\Femanagersignalslot\Domain\Service;
class SendMailService
{
/**
* Send mail about user information
*
* @param \In2code\Femanager\Domain\Model\User $user
* @param \In2code\Femanager\Controller\NewController $pObj
* @return void
*/
public function send($user, $pObj)
{
$message = '
New user registered
Username: ' . $user->getUsername() . '
Email: ' . $user->getEmail() . '
';
mail('your@email.com', 'SignalSlot Test', $message);
}
}