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

File

Located in

Signal Name

Available Parameters

Description

NewController.php

createAction()

createActionBeforePersist

$user, $this

Use this signal if you want to hook into the process before the new user was persisted

NewController.php

confirmCreateRequestAction()

confirmCreateRequestActionBeforePersist

$user, $hash, $status, $this

Use this signal if you want to hook into the confirmation process

NewController.php

createAdminConfirmationRequest()

createAdminConfirmationRequestAutoConfirm

$user, $this

Signal if a user was auto-confirmed

NewController.php

createAdminConfirmationRequest()

createAdminConfirmationRequestManualConfirmation

$user, $this

Signal if a user was not auto-confirmed and must be confirmed manually

EditController.php

updateAction()

updateActionBeforePersist

$user, $this

Use this signal if you want to hook into the process before the user- profile was updated

EditController.php

confirmUpdateRequestAction()

confirmUpdateRequestActionAfterPersist

$user, $hash, $status, $this

Use this signal if you want to hook after a profile was accepted or refused

EditController.php

deleteAction()

deleteAction

$user, $this

Use this signal if you want to hook into the process before the user- profile will be deleted

InvitationController.php

createAction()

confirmUpdateRequestActionBeforePersist

$user, $hash, $status, $this

Use this signal if you want to hook into the process before a new user was persisted

InvitationController.php

createAllConfirmed()

createAllConfirmedAfterPersist

$user, $this

Use this signal if you want to hook into the process after a new user was persisted

InvitationController.php

editAction()

editActionAfterPersist

$user, $hash, $this

Use this signal if you want to hook into the process before a user adds a new password (step 1)

InvitationController.php

updateAction()

updateActionAfterPersist

$user, $this

Use this signal if you want to hook into the process after a user adds a new password (step 2)

UserController.php

loginAsAction()

loginAsAction

$user, $this

Use this signal if you want to hook into the process after you simulate a frontend user login

UserBackendController.php

confirmUserAction()

confirmUserAction

$user, $this

Signal if a user profile was confirmed in backend module

UserBackendController.php

refuseUserAction()

refuseUserAction

$user, $this

Signal if a user profile was refused in backend module

AbstractController.php

finalCreate()

finalCreateAfterPersist

$user, $action, $this

Use this signal if you want to hook into the process after the new user was persisted

AbstractController.php

updateAllConfirmed()

updateAllConfirmedAfterPersist

$user, $this

Use this signal if you want to hook into the process after the new user was persisted

?

?

?

?

Do you need a new Signal in femanager? Just request one on https://github.com/in2code-de/femanager

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(
				),
		),
);
Copied!

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 = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
$signalSlotDispatcher->connect(
	'In2code\Femanager\Controller\NewController',
	'createActionBeforePersist',
	'In2code\Femanagersignalslot\Domain\Service\SendMailService',
	'send',
	FALSE
);
Copied!

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