Tag typoscript

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

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