[TYPO3-dev] Hook in auth service

Michael Miousse michael.miousse at infoglobe.ca
Wed Nov 5 14:05:17 CET 2008


Rudy Gnodde wrote:

> Hello everyone,
> 
> I have an auth service which logs users in using an external login
> service. This works fine. However the external login service does not
> give a lot of data about the user, only a unique id. This unique id can
> be used to get the data from a different source. No problems so far.
> 
> Now I want to release this extension so other people can also use it.
> However the external source for the user data does not have to be the
> same for other people. So I want to create a hook in the auth service
> where people can connect to their own user data source. This is done
> using the following code (copied from tt_news):
> 
> if
> (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['myextensionkey'
['userInfoHooks']))
> {
> foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['myextensionkey'
['userInfoHooks']
> as $_classRef) {
> $_procObj = & t3lib_div::getUserObj($_classRef);
> $user = $_procObj->userInfoProcessor($user);
> }
> }
> 
> This should work fine as far as I can see. I then add the following code
> to typo3conf/extTables.php:
> 
> require_once(t3lib_extMgm::extPath('myextensionkey') .
> 'sv1/class.tx_myextensionkey_userext.php');
> $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['myextensionkey']['userInfoHooks'
[]
> = 'tx_myextensionkey_userext';
> 
> When I tries to test it it didn't work. It seems the
> $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['myextensionkey']['userInfoHooks']
> array is empty. So extTables.php probably isn't loaded yet.
> 
> So I try to put the code in typo3conf/localconf.php instead. This causes
> an error in t3lib_extMgm::extPath because the extension hasn't been
> loaded yet.
> 
> My first question is: Is this the correct way to make a hook into my
> service?

yes it is, hooks are the best way to allow people to customize your
extension. the other way would be xclass but the major problem with xclass
is that you can only do one xclass on a class and you can't do xclass on
any class. So hooks are a good tool for developper to ensure that their
extensions are fully customizable.

> My second question is: Where is the best place to add things to the hook
> and what is the best way to do it?
the rigth place for $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['myextensionkey'
['userInfoHooks'] is in localconf. Ext_table is for the configuration of
items your extension create.

the require_once you put is useless because if you intend to use a hook from
extension a, you don't have to load any class from this extension because
those class should already be loaded. You can't use a hook from extension a
without having a installed. So if extension a is installed you don't need
to include any of her class. 

> 
> Thanks,
> 
> Rudy Gnodde
> WIND Internet

-- 
Michael Miousse
Infoglobe
michael.miousse at infoglobe.ca




More information about the TYPO3-dev mailing list