During work on my extension cwenvbanner to make it compatible with Typo3 CMS 7.2, I came across a good old friend, the hooks array $GLOBALS[‘TYPO3_CONF_VARS’][‘SC_OPTIONS’]. Since I sometimes struggle with the way how to declare the class and function to be called, I decided to write it down here – once and for all 🙂
EXT:name_of_extension/path_and_filename_of_class:{&}classname->functionName
The ampersand before the class name is optional. If you add it, the class will be instantiated using the Singleton pattern.
Let’s have some examples. Firstly, let’s have a look at the old version I had in my extension:
[code lang=”php”]
$GLOBALS[‘TYPO3_CONF_VARS’][‘SC_OPTIONS’][‘tslib/class.tslib_fe.php’][‘contentPostProc-output’][‘tx_cwenvbanner’]
= ‘EXT:cwenvbanner/class.tx_cwenvbanner.php:&tx_cwenvbanner->contentPostProc_output’;
[/code]
For the new Typo3 CMS 7 compatible version of cwenvbanner I wanted to use a namespaced classes for the heck of it. I came up with the inspiring name “Main” which now resides in the Classes directory of the extension, so need I changed the path and filename accordingly. I also need to provide the fully qualified class name, i.e. Cw\Cwenvbanner\Main.
This is how it looks like now:
[code lang=”php”]
$GLOBALS[‘TYPO3_CONF_VARS’][‘SC_OPTIONS’][‘tslib/class.tslib_fe.php’][‘contentPostProc-output’][‘tx_cwenvbanner’]
= ‘EXT:cwenvbanner/Classes/Main.php:&Cw\\Cwenvbanner\\Main->contentPostProc_output’;
[/code]