Articles by author Alex

Readout of TypoScript with eID and BE-Modul

Sometimes you have to get TypoScript values in different places. The following will illustrate two problems that proved me.

TypoScript with eID

The script being called via eID is kind of lightweight and does not load a fully features TYPO3 core. User as well as database are initialized quickly but if you want to use values from TypoScript this unfortunately cannot be achieved with two lines of code. You at least need to transfer the page id to the eID script - I'm using a GET variable - to correctly initialize the TSFE. Then just instantiate a tslib_fe class, connect to the database, initialize the user, template and config and you're done:

// eID specific initialization of user and database
tslib_eidtools::connectDB();
tslib_eidtools::initFeUser();

// initialize TSFE
require_once(PATH_tslib.'class.tslib_fe.php');
require_once(PATH_t3lib.'class.t3lib_page.php');
$temp_TSFEclassName = t3lib_div::makeInstanceClassName('tslib_fe');
$GLOBALS['TSFE'] = new $temp_TSFEclassName($TYPO3_CONF_VARS, $pid, 0, true);
$GLOBALS['TSFE']->connectToDB();
$GLOBALS['TSFE']->initFEuser();
$GLOBALS['TSFE']->determineId();
$GLOBALS['TSFE']->getCompressedTCarray();
$GLOBALS['TSFE']->initTemplate();
$GLOBALS['TSFE']->getConfigArray();

Now access the data in the well-known way:

$GLOBALS['TSFE']->tmpl->setup['plugin.']['extensionkey.']['your_value']

By the way: with this line of code you can readout the TypoScript in not fully initialized plugins, too.

TypoScript in backend modules

Sometimes there is the necessity to access TypoScript in backend modules, e.g. when sending an email to readout the sender. The process is similiar to the eID approach but we determine the root page id ourself and use the t3lib_pageSelect and t3lib_tsparser_ext classes. I wrapped it into a function:

/**
 * Loads the TypoScript for the given extension prefix, e.g. tx_cspuppyfunctions_pi1, for use in a backend module.
 *
 * @param string $extKey
 * @return array
 */
function loadTypoScriptForBEModule($extKey) {
    require_once(PATH_t3lib . 'class.t3lib_page.php');
    require_once(PATH_t3lib . 'class.t3lib_tstemplate.php');
    require_once(PATH_t3lib . 'class.t3lib_tsparser_ext.php');
    list($page) = t3lib_BEfunc::getRecordsByField('pages', 'pid', 0);
    $pageUid = intval($page['uid']);
    $sysPageObj = t3lib_div::makeInstance('t3lib_pageSelect');
    $rootLine = $sysPageObj->getRootLine($pageUid);
    $TSObj = t3lib_div::makeInstance('t3lib_tsparser_ext');
    $TSObj->tt_track = 0;
    $TSObj->init();
    $TSObj->runThroughTemplates($rootLine);
    $TSObj->generateConfig();
    return $TSObj->setup['plugin.'][$extKey . '.'];
}

And now we have some less problems...

Function/Class '...' was not prepended with 'user_'

I'm currently configuring one of my extension for realurl within Typo3. My aim is to have the categories and subcategories of an article center within the url. But the functionality of lookUpTable does not suffice as I have to observe the nesting of the categories. So I choose userFunc and enter the values as given in the realurl documentation:

'fixedPostVars' => array(
    'articlecenter' => array(
        'userFunc' => 'EXT:extkey/class.tx_userxyz.php:
            &tx_realurl_userfunctest->main',
    ),
),

then I clear the cache and it happens... nothing. Only a nice error message is presented:

|Function/Class 'E' was not prepended with 'user_'|

Seems that my configured values do not really reach the code they should. And of course that's the way it is. After some searching I detect that my configuration is wrong, because realurl is putting all configured values into a nested array wherein every key-value pair is put in as an array that has a numeric indice in the big array. (I hope you can follow my poor english). But my "userFunc" is not set up this way, its numeric indice is userFunc and the array with the key-value pairs is the string EXT:realurl/class.tx_realurl_userfunctest.php:&tx_realurl_userfunctest->main. As realurl runs through this array using foreach it has only "E" as value (that comes from the "EXT") and furthermore the error is thrown in t3lib_div:callUserFunction. Now the solution is quite easy, simply nest the userFunc within an additional array:

'fixedPostVars' => array(
    'articlecenter' => array(
        array(
            'userFunc' => 'EXT:extkey/class.tx_userxyz.php:
                &tx_realurl_userfunctest->main',
        ),
    ),
),

Now everything is working again. You only need to find it out...

eSteak - hot MooTools slices

By now there are many javascript frameworks available that make programming easy and encapsulate new and cool functionalities. Surely every framework has its advantages and disadvantages but in my opinion you can't switch between all of them - you have to deceide in favour of one. In my case I have chosen Mootools, as you may have already seen here... A friend of mine and also a co-worker, Grundi, has created a site that answers to the beautiful name of "eSteak" that unites the different scripts for Mootools on a central place, with rating, Mootools dependency listing and so on. The whole thing is user generated content, so its up to all the Mootools developers and even to you to upload scripts and support it! Because the problem with Mootools is that there are really cool scripts out there, but you first have to find them. I hope that eSteak will be filled with a lot of scripts and that it will develop to the central place for Mootools friends and enthusiasts.

Update (somewhen in 2013): unfortunately eSteak was taken to the grave in 2010 - check this blog post for more information: http://blog.aplusmedia.de/2010/10/19/esteak-net-end-of-life-announcement/