Commit 40f85920 authored by Kevin von Spiczak's avatar Kevin von Spiczak

Merge branch 'Feature_ReplacementInBackend-1564' into 'master'

Feature replacement in backend 1564

See merge request typo3/content_replacer!2
parents 9f2712e7 b7487b77
......@@ -24,14 +24,17 @@ namespace SGalinski\ContentReplacer\Controller;
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\TimeTracker\NullTimeTracker;
use SGalinski\ContentReplacer\Repository\TermRepository;
use SGalinski\ContentReplacer\Service\AbstractParserService;
use SGalinski\ContentReplacer\Service\CustomParserService;
use SGalinski\ContentReplacer\Service\SpanParserService;
use SGalinski\ContentReplacer\Utility\ExtensionUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Frontend\Page\PageGenerator;
/**
* Controlling code of the extension "content_replacer"
......@@ -66,10 +69,60 @@ class MainController {
* settings.
*
* @return array
* @throws \TYPO3\CMS\Core\Error\Http\PageNotFoundException
* @throws \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException
* @throws \TYPO3\CMS\Core\Http\ImmediateResponseException
*/
public function prepareConfiguration() {
if (TYPO3_MODE === 'BE') {
/** @var TypoScriptFrontendController $typoScriptFrontendController */
$typoScriptFrontendController = $GLOBALS['TSFE'];
if (!($typoScriptFrontendController instanceof TypoScriptFrontendController)) {
$typoScriptFrontendController = $GLOBALS['TSFE'] = new TypoScriptFrontendController(
$GLOBALS['TYPO3_CONF_VARS'], 0, 0
);
}
// required in order to generate the menu links later on
$currentVersion = VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version);
if ($currentVersion >= 9000000) {
$typoScriptFrontendController->settingLanguage();
$typoScriptFrontendController->newCObj();
} else {
if (!is_object($GLOBALS['TT'])) {
$GLOBALS['TT'] = new NullTimeTracker();
}
if ($currentVersion < 8000000) {
// prevents a possible crash
$typoScriptFrontendController->getPageRenderer()->setBackPath('');
}
$typoScriptFrontendController->initFEuser();
$typoScriptFrontendController->initUserGroups();
$typoScriptFrontendController->fetch_the_id();
$typoScriptFrontendController->getPageAndRootline();
$typoScriptFrontendController->initTemplate();
$typoScriptFrontendController->no_cache = TRUE;
$typoScriptFrontendController->getConfigArray();
$typoScriptFrontendController->settingLanguage();
$typoScriptFrontendController->settingLocale();
$typoScriptFrontendController->convPOSTCharset();
$typoScriptFrontendController->absRefPrefix = '/';
PageGenerator::pagegenInit();
$typoScriptFrontendController->newCObj();
}
}
$extensionConfiguration = ExtensionUtility::getExtensionConfiguration();
$typoscriptConfiguration = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_content_replacer.'];
if (TYPO3_MODE === 'BE') {
$configurationManager = GeneralUtility::makeInstance(BackendConfigurationManager::class);
$extbaseFrameworkConfiguration = $configurationManager->getTypoScriptSetup();
$typoscriptConfiguration = $extbaseFrameworkConfiguration['plugin.']['tx_content_replacer.'];
} else {
$typoscriptConfiguration = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_content_replacer.'];
}
if (is_array($typoscriptConfiguration)) {
foreach ($typoscriptConfiguration as $key => $value) {
$extensionConfiguration[$key] = $value;
......@@ -176,12 +229,15 @@ class MainController {
/**
* Controlling code
*
* if $overwriteConfiguration is set, it overwrites $this->extensionConfiguration
* @param string $content
* @param array $overwriteConfiguration
* @return string
* @throws \InvalidArgumentException
*/
public function main($content) {
public function main($content, array $overwriteConfiguration = []) {
if ($overwriteConfiguration) {
$this->extensionConfiguration = $overwriteConfiguration;
}
$spanParser = $this->getSpanParser();
$content = $this->parseAndReplace($spanParser, $content);
......
......@@ -27,6 +27,7 @@ namespace SGalinski\ContentReplacer\Service;
use SGalinski\ContentReplacer\Repository\TermRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
/**
......@@ -98,6 +99,14 @@ abstract class AbstractParserService {
/** @var $tsfe TypoScriptFrontendController */
$tsfe = $GLOBALS['TSFE'];
if (TYPO3_MODE === 'BE') {
$configurationManager = GeneralUtility::makeInstance(BackendConfigurationManager::class);
$extbaseFrameworkConfiguration = $configurationManager->getTypoScriptSetup();
$typoscriptConfiguration = $extbaseFrameworkConfiguration['plugin.']['tx_content_replacer.'][$stdWrap . '.'];
} else {
$typoscriptConfiguration = $tsfe->tmpl->setup['plugin.']['tx_content_replacer.'][$stdWrap . '.'];
}
if ($replacement !== '') {
$replacement = $tsfe->cObj->parseFunc($replacement, $this->parseFunc);
$replacement = preg_replace('/^<p>(.+)<\/p>$/s', '\1', $replacement);
......@@ -106,7 +115,7 @@ abstract class AbstractParserService {
if ($stdWrap !== '') {
$replacement = $tsfe->cObj->stdWrap(
($replacement === '' ? $termName : $replacement),
$tsfe->tmpl->setup['plugin.']['tx_content_replacer.'][$stdWrap . '.']
$typoscriptConfiguration
);
}
......
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