Romain CANON
Développeur Web passionné, spécialisé dans TYPO3. Joueur de StarCraft II et DotA 2. Fan de Led Zepp'.



Récupérer la configuration TypoScript d'une page


Les développeurs TYPO3 sont souvent amenés à récupérer la configuration TypoScript d'une page en particulier, voire la configuration complète d'une instance TYPO3.

Je vous partage donc une fonction assez générale, qui permet de récupérer cette configuration, d'à peu près n'importe où (Backend, Frontend, UserFunc, eID).

/**
 * Returns the TypoScript configuration of a given page as an array.
 *
 * @param int $uid	The uid of the page you want the TypoScript configuration from. If none given, the full configuration is used.
 * @return array
 */
public static function getPageConfiguration($uid = NULL) {
	/** @var $objectManager \TYPO3\CMS\Extbase\Object\ObjectManager */
	$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('\\TYPO3\\CMS\\Extbase\\Object\\ObjectManager');

	/** @var $typoScriptService \TYPO3\CMS\Extbase\Service\TypoScriptService */
	$typoScriptService = $objectManager->get('\\TYPO3\\CMS\\Extbase\\Service\\TypoScriptService');

	if ($uid && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($uid) && $uid > 0) {
		/** @var $pageRepository \TYPO3\CMS\Frontend\Page\PageRepository */
		$pageRepository = $objectManager->get('\\TYPO3\\CMS\\Frontend\\Page\\PageRepository');
		$rootLine = $pageRepository->getRootLine($uid);

		/** @var $templateService \TYPO3\CMS\Core\TypoScript\TemplateService */
		$templateService = $objectManager->get('\\TYPO3\\CMS\\Core\\TypoScript\\TemplateService');
		$templateService->tt_track = 0;
		$templateService->init();
		$templateService->runThroughTemplates($rootLine);
		$templateService->generateConfig();

		$fullConfiguration = $typoScriptService->convertTypoScriptArrayToPlainArray($templateService->setup);
	}
	else {
		/** @var $configurationManager \TYPO3\CMS\Extbase\Configuration\ConfigurationManager */
		$configurationManager = $objectManager->get('\\TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');

		$fullConfiguration = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);

		if (is_array($fullConfiguration) && !empty($fullConfiguration)) {
			$fullConfiguration = $typoScriptService->convertTypoScriptArrayToPlainArray($fullConfiguration);
		}
	}

	return $fullConfiguration;
}