Tag typo3

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...

TYPO3: Limit creatable elements per page

Sometimes it is necessary to limit the creatable elements on a page. This is especially useful if you only want to save specific elements within a SysFolder, e.g. within "users" there should be only users.

Within the TSConfig of the appropriate page add the following TypoScript having db_tablename be the database table with the elements you want to limit to:

mod.web_list.allowedNewTables = db_tablename,db_tablename_2