我想要的是将纯文本转换为HTML代码,例如some plain text
到<p>some plain text</p>
我尝试了以下ContentObjectRenderer
/** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject */
$contentObject = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
return $contentObject->parseFunc($bodytext, array(), '< lib.parseFunc_RTE');
然而,它根本不起作用。我是否必须初始化$GLOBALS['TSFE']
或什么?
答案 0 :(得分:1)
请查看simulateFrontendEnvironment()
。您会看到它们使用$GLOBALS['TSFE']
方法构建/**
* Copies the specified parseFunc configuration to $GLOBALS['TSFE']->tmpl->setup in Backend mode
* This somewhat hacky work around is currently needed because the parseFunc() function of \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer relies on those variables to be set
*/
protected static function simulateFrontendEnvironment()
{
self::$tsfeBackup = isset($GLOBALS['TSFE']) ? $GLOBALS['TSFE'] : null;
$GLOBALS['TSFE'] = new \stdClass();
$GLOBALS['TSFE']->tmpl = new \stdClass();
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
$GLOBALS['TSFE']->tmpl->setup = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
}
并在cObj处理后删除它。
{{1}}
将您需要的所有内容复制到您的扩展程序中,它应该可以正常工作