【发布时间】:2019-03-05 10:33:52
【问题描述】:
我想根据一些数据动态加载插件。首先我尝试用 Typoscript 来做,但经过一些研究我发现,无法更改插件的设置 (see old forum entry)。
我需要根据传递的数据更改settings.simplepoll.uid:
这是我试过的 Typoscript:
lib.loadSimplepoll = USER
lib.loadSimplepoll {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
extensionName = Simplepoll
pluginName = Polllisting
vendorName = Pixelink
switchableControllerActions {
SimplePoll {
1 = list
}
}
settings < plugin.tx_simplepoll.settings
settings {
simplepoll {
uid.current = 1
}
}
}
模板中的调用如下所示:
<f:cObject typoscriptObjectPath="lib.loadSimplepoll">{newsItem.simplepoll}</f:cObject>
在弄清楚无法更改设置后,我尝试了查看助手:
<?php
namespace Vendor\Extension\ViewHelpers;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class LoadSimplepollViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
{
/**
* @param int $uid Uid of poll
* @return string
*/
public function render($uid) {
$cObj = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer');
$configurationManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
$simplepollTs = $configurationManager->getConfiguration(
\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS,
'simplepoll',
'Polllisting'
);
$ttContentConfig = array(
'tables' => 'tt_content',
'source' => 1030,
'dontCheckPid' => 1
);
// returning this works perfectly!
// but I need to change the "settings.simplepoll.uid"
$data = $cObj->RECORDS($ttContentConfig);
$cObj->start($data, 'tx_simplepoll_domain_model_simplepoll');
$renderObjName = '<tt_content.list.20.simplepoll_polllisting';
$renderObjConf = $GLOBALS['TSFE']->tmpl->setup['tt_content.']['list.']['20.']['simplepoll_polllisting.'];
$renderObjConf['persistence']['storagePid'] = 394; // This does not work!
$renderObjConf['settings'] = $simplepollTs;
$renderObjConf['settings']['simplepoll']['uid'] = $uid;
return $cObj->cObjGetSingle($renderObjName, $renderObjConf);
}
}
viehelper 是这样调用的:
{vh:LoadSimplepoll(uid: '{newsItem.simplepoll}')}
现在我可以用这一行更改投票的uid:
$renderObjConf['settings']['simplepoll']['uid'] = $uid;
我现在的问题是,它加载了投票,但没有加载答案。我追查到这个事实,插件不知何故不再知道Record Storage Page。 $renderObjConf['persistence']['storagePid'] = 394; 行没有帮助。
如何告诉插件Storage Pid?
或者是否有另一种/更好的方法来加载具有变化数据的插件?
【问题讨论】:
标签: typo3 typoscript extbase view-helpers