我有以下问题: 我们使用自定义列覆盖tt_content TCA,该列在其配置中包含itemsProcFunc。在函数中我们尝试检索TypoScript-Settings,因此我们可以动态显示项目。问题是:在我们没有接收所有TypoScript设置的功能中,包括但只有一些。
'itemsProcFunc' => 'Vendor\Ext\Backend\Hooks\TcaHook->addFields',
class TcaHook
{
public function addFields($config){
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$configurationManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
$setup = $configurationManager->getConfiguration(
\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT
);
}
$ setup 现在不完整,并且不包含完整的TypoScript,例如缺少一些静态包含的TypoScript。
在作曲家模式中使用TYPO3 7 LTS(7.6.18),PHP 7.0。*。
有人知道问题出在哪里吗?还有其他选择吗?
答案 0 :(得分:1)
你可能误解了TypoScipt的目的。这是前端的配置方式。您提到的Hook用于TCA,它是TYPO3的后端部分。 TypoScript通常不用于后端相关的东西,因为它绑定到特定的页面模板记录。而在后端,有TSConfig,可以绑定到页面,但也可以全局添加。你做错的另一件事是使用ObjectManager和ConfigurationManager,它们是extbase的类,它在后端没有初始化。我建议不要在TCA中使用extbase,因为TCA是为每个页面请求缓存和加载的。而是使用TSConfig或直接将配置设置提供给TCA。不要初始化extbase,也不要在这些钩子中使用extbase类。 根据您要通过TypoScript配置的内容,您可能需要执行以下操作:
'config' => [
'type' => 'select',
'renderType' => 'singleSelect',
'items' => [
['EXT:my_ext/Resources/Private/Language/locallang_db.xlf:myfield.I.0', '']
],
'itemsProcFunc' => \VENDOR\MyExt\UserFunctions\FormEngine\TypeSelectProcFunc::class . '->fillSelect',
'customSetting' => 'somesetting'
]
然后在您的班级中访问它:
class TypeSelectProcFunc{
public function fillSelect(&$params){
if( $params['customSetting'] === 'somesetting' ){
$params['items'][] = ['New item',1];
}
}
}
答案 1 :(得分:0)
我遇到了类似的问题(还有 itemsProcFunc
和检索 TypoScript)。就我而言,ConfigurationManager 不知道所选后端页面的当前页面 ID。因此,它使用了根页面的页面 ID(例如 1),并且未加载某些 TypoScript 模板。
然而,在我们研究解决方案之前,Euli 提出了一些好观点in his answer:
您可能想问另一个问题,您打算具体做什么以及为什么需要在 BE 上下文中使用 TypoScript。
为了完整起见,我测试了这个解决方法,但由于上述原因,我不推荐它,因为我不确定这是否是最佳实践。 (我使用它只是因为我正在修补一个已经在 TCA 中使用 TypoScript 的扩展,我想找出它为什么不起作用。我可能会完全重做这部分。)
我发这个帖子是希望对类似问题有帮助。
public function populateItemsProcFunc(array &$config): array
{
// workaround to set current page id for BackendConfigurationManager
$_GET['id'] = $this->getPageId((int)($config['flexParentDatabaseRow']['pid'] ?? 0));
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$configurationManager = $objectManager->get(BackendConfigurationManager::class);
$setting = $configurationManager->getTypoScriptSetup();
$templates = $setting['plugin.']['tx_rssdisplay.']['settings.']['templates.'] ?? [];
// ... some code removed
}
protected function getPageId(int $pid): int
{
if ($pid > 0) {
return $pid;
}
$row = BackendUtility::getRecord('tt_content', abs($pid), 'uid,pid');
return $row['pid'];
}
函数 getPageId()
派生自 ext:news,它也在 itemsProcFunc 中使用它,但它随后从 TSconfig 检索配置。您可能还想查看示例:ext:news GeorgRinger\News\Hooks\ItemsProcFunc::user_templateLayout
如果你查看TYPO3核心中的代码,它会尝试从
获取当前页面id(int)GeneralUtility::_GP('id');
这通常会被设置,但在 itemsProcFunc 中可能不会(我在 TYPO3 10.4.14 中就是这种情况)。