Commit d5e27f74 authored by Stefan Froemken's avatar Stefan Froemken Committed by Thomas Löffler

Remove TypoScript Utility

TypoScript Utility removes dots from TypoScript array
which was already done by extbase framework.
parent 05b83338
Pipeline #2572 passed with stages
in 2 minutes and 11 seconds
......@@ -34,7 +34,7 @@ abstract class AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\Acti
}
/**
* Pre-parse TypoScript setup
* Check, if TS Template was included
*
* @return void
* @throws \Exception
......@@ -45,7 +45,6 @@ abstract class AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\Acti
if (!is_array($this->settings)) {
throw new \Exception('Static template "Default Configuration" of ter_fe2 has to be inserted before this plugin can be shown in frontend');
}
$this->settings = \T3o\TerFe2\Utility\TypoScript::parse($this->settings);
}
/**
......
<?php
namespace T3o\TerFe2\Utility;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* Utilities to manage and convert Typoscript Code
*/
class TypoScript
{
/**
* @var object
*/
protected static $frontend;
/**
* @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
*/
protected static $contentObject;
/**
* @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManager
*/
protected static $configurationManager;
/**
* Initialize configuration manager and content object
*
* @return void
*/
protected static function initialize()
{
// Get configuration manager
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
self::$configurationManager = $objectManager->get(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::class);
// Simulate Frontend
if (TYPO3_MODE != 'FE') {
self::simulateFrontend();
self::$configurationManager->setContentObject($GLOBALS['TSFE']->cObj);
}
// Get content object
self::$contentObject = self::$configurationManager->getContentObject();
if (empty(self::$contentObject)) {
self::$contentObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
}
}
/**
* Simulate a frontend environment
*
* @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj Instance of an content object
* @return void
*/
public static function simulateFrontend(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj = null)
{
// Make backup of current frontend
self::$frontend = (!empty($GLOBALS['TSFE']) ? $GLOBALS['TSFE'] : null);
// Create new frontend instance
$GLOBALS['TSFE'] = new \stdClass();
$GLOBALS['TSFE']->cObjectDepthCounter = 100;
$GLOBALS['TSFE']->cObj = (!empty($cObj) ? $cObj : \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class));
if (empty($GLOBALS['TSFE']->sys_page)) {
$GLOBALS['TSFE']->sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
}
if (empty($GLOBALS['TSFE']->tmpl)) {
$GLOBALS['TSFE']->tmpl = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\TemplateService::class);
$GLOBALS['TSFE']->tmpl->getFileName_backPath = PATH_site;
$GLOBALS['TSFE']->tmpl->init();
}
if (empty($GLOBALS['TT'])) {
$GLOBALS['TT'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TimeTracker\NullTimeTracker::class);
}
if (empty($GLOBALS['TSFE']->config)) {
$GLOBALS['TSFE']->config = \TYPO3\CMS\Core\Utility\GeneralUtility::removeDotsFromTS(self::getSetup());
}
}
/**
* Reset an existing frontend environment
*
* @param object $frontend Instance of a frontend environemnt
* @return void
*/
public static function resetFrontend($frontend = null)
{
$frontend = (!empty($frontend) ? $frontend : self::$frontend);
if (!empty($frontend)) {
$GLOBALS['TSFE'] = $frontend;
}
}
/**
* Returns unparsed TypoScript setup
*
* @param string $typoScriptPath TypoScript path
* @return array TypoScript setup
*/
public static function getSetup($typoScriptPath = '')
{
if (empty(self::$configurationManager)) {
self::initialize();
}
$setup = self::$configurationManager->getConfiguration(
\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::CONFIGURATION_TYPE_FULL_TYPOSCRIPT
);
if (empty($typoScriptPath)) {
return $setup;
}
$path = explode('.', $typoScriptPath);
foreach ($path as $segment) {
if (empty($setup[$segment . '.'])) {
return array();
}
$setup = $setup[$segment . '.'];
}
return $setup;
}
/**
* Parse given TypoScript configuration
*
* @param array $configuration TypoScript configuration
* @param boolean $isPlain Is a plain "Fluid like" configuration array
* @return array Parsed configuration
*/
public static function parse(array $configuration, $isPlain = true)
{
if (empty(self::$contentObject)) {
self::initialize();
}
// Convert to classic TypoScript array
if ($isPlain) {
/** @var \TYPO3\CMS\Core\TypoScript\TypoScriptService $typoScriptService */
$typoScriptService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\TypoScriptService::class);
$configuration = $typoScriptService->convertPlainArrayToTypoScriptArray($configuration);
}
// Parse configuration
return self::parseTypoScriptArray($configuration);
}
/**
* Parse TypoScript array
*
* @param array $configuration TypoScript configuration array
* @return array Parsed configuration
* @api
*/
public static function parseTypoScriptArray(array $configuration)
{
$typoScriptArray = array();
if (is_array($configuration)) {
foreach ($configuration as $key => $value) {
$ident = rtrim($key, '.');
if (is_array($value)) {
if (!empty($configuration[$ident])) {
$typoScriptArray[$ident] = self::$contentObject->cObjGetSingle($configuration[$ident], $value);
} else {
$typoScriptArray[$ident] = self::parseTypoScriptArray($value);
}
unset($configuration[$key]);
} elseif (is_string($value) && $key === $ident) {
$typoScriptArray[$key] = $value;
}
}
}
return $typoScriptArray;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment