TYPO3:通过Typoscript或ViewHelper呈现插件并更改设置
我想根据一些数据动态加载插件。首先我试着用打字稿来做,但经过一些研究,我发现不可能更改插件()的设置TYPO3:通过Typoscript或ViewHelper呈现插件并更改设置,typo3,typoscript,extbase,view-helpers,Typo3,Typoscript,Extbase,View Helpers,我想根据一些数据动态加载插件。首先我试着用打字稿来做,但经过一些研究,我发现不可能更改插件()的设置 我需要根据传递的数据更改设置.simplepoll.uid: 这是我试过的打字稿: lib.loadSimplepoll = USER lib.loadSimplepoll { userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run extensionName = Simplepoll pluginName = Pollli
我需要根据传递的数据更改
设置.simplepoll.uid
:
这是我试过的打字稿:
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
}
}
}
现在,我可以使用以下行更改投票的uid
:
$renderObjConf['settings']['simplepoll']['uid']=$uid代码>
我现在的问题是,它加载的是民意测验,而不是答案。我追踪到这样一个事实,即插件不知何故不再知道记录存储页面
。行$renderObjConf['persistence']['storagePid']=394代码>没有帮助
我怎样才能告诉插件存储Pid
或者有没有其他/更好的方法来加载带有更改数据的插件?为什么不能在打字脚本中修改设置.simplepoll.uid
您只需要使用正确的构造来修改它
对于单个值,可以使用当前值,但要正确使用。这是一个需要评估的stdWrap函数。
如果默认情况下没有stdWrap
评估,则它可能与类型为TEXT
settings.simplepoll.uid.cObject = TEXT
settings.simplepoll.uid.cObject.current = 1
或者要指示一个stdWrap
,您需要按字面意思使用stdWrap
:
settings.simplepoll.uid.stdWrap.current = 1
数据传输的另一个变体是命名参数。只需构建一个关联数组作为数据参数,并访问各个值:
流体:
<f:cObject typoscriptObjectPath="lib.arraytest" data="{a:'abc',b:'xyz'}" >
inside text
</f:cObject>
这将导致输出/abc/\xyz\
。请注意:f:cobject
标记的内部文本将丢失,因为数据参数具有关于内部子项的优先级为什么不能在打字脚本中修改设置.simplepoll.uid
因为扩展simplepoll不会将任何stdWrap功能处理到其打字脚本设置中
查看代码:
此特殊设置用于:
没有stdWrap,只是简单的用法
将其与ext:news
进行比较:
在使用任何设置之前,都会对其进行处理。打字脚本设置与插件中设置的专用连接。如有必要,还可以使用stdWrap:
如您所见:
extbase不支持您使用打字脚本stdWrap功能。
您(和每个扩展作者)都需要手工完成。但即使在extbase之前也是如此
这样:由于您无法配置您的值,您只能欺骗TYPO3(以及插件):
如果有少量uid,则每个uid可以有一个变体
lib.loadSimplepoll123 < lib.loadSimplepoll
lib.loadSimplepoll123.settings.simplepoll.uid = 123
lib.loadSimplepoll234 < lib.loadSimplepoll
lib.loadSimplepoll234.settings.simplepoll.uid = 234
lib.loadSimplepoll345 < lib.loadSimplepoll
lib.loadSimplepoll345.settings.simplepoll.uid = 345
lib.loadSimplepoll456 < lib.loadSimplepoll
lib.loadSimplepoll456.settings.simplepoll.uid = 456
lib.loadSimplepoll 123
就这样说吧
<f:cObject typoscriptObjectPath="lib.loadSimplepoll{newsItem.simplepoll}" />
或者,您构建一个实现stdWrap功能的pull请求,并将其发送给扩展作者。与此同时,我让ViewHelper开始工作:
Viewhelper:
<?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);
}
}
<?php
namespace Vendor\Extension\ViewHelpers;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class LoadSimplepollViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
{
/**
* @return void
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('simplepollUid', 'int', 'Uid of simplepoll', false);
}
/**
* @return string
*/
public function render()
{
$configurationManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
$simplepollTs = $configurationManager->getConfiguration(
\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS,
'simplepoll',
'Polllisting');
$cObj = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer');
$renderObjName = '<tt_content.list.20.simplepoll_polllisting';
$renderObjConf = $GLOBALS['TSFE']->tmpl->setup['tt_content.']['list.']['20.']['simplepoll_polllisting.'];
$renderObjConf['settings'] = $simplepollTs;
$renderObjConf['settings']['simplepoll']['uid'] = (int)$this->arguments['simplepollUid'];
return $cObj->cObjGetSingle($renderObjName, $renderObjConf);
}
}
就是这样。我想我以前试过这两个版本(因为在链接的论坛帖子中提到了它们),但都不起作用:settings.simplepoll.uid.stdWrap.current=1
将在SimplePollController中为$this->settings['simplepoll']生成一个数组(['uid'['stdWrap']['current']=1
)和settings.simplepoll.uid.cObject=TEXT…
生成一个SQL错误:从tx\u simplepoll\u domain\u model\u simplepoll.*选择tx\u simplepoll\u domain\u model\u model\u simplepoll.uid='1',“TEXT”和tx\u simplepoll\u domain\u model\u simplepoll.deleted=0…
设置。simplepoll.uid
可能没有stdWrapcObject
也需要stdWrap。在论坛帖子中,我怀疑最后一篇帖子给出了一个解决方案,override
也基于stdWrap
。您是否尝试过使用覆盖.cobject.TEXT
?(在渲染时,所有temp.
对象不再存在。@BerndWilkeπφI已尝试settings.simplepoll.useStdWrap=uid settings.simplepoll{uid.override.cObject
运气不佳。temp.pollUid
返回投票的uid。我做错了什么吗?再次感谢您的帮助!我添加了关于此案例的另一个答案(分机:simplepoll)似乎不支持任何灵活性。哇,非常感谢您的研究和帮助!通过修改上述新闻扩展的代码,它正在工作。结论:默认情况下,通过打字输入加载扩展时,无法更改设置。
$simplePoll = $this->simplePollRepository->findByUid($this->settings['simplepoll']['uid']);
$this->originalSettings = $originalSettings;
// Use stdWrap for given defined settings
if (isset($originalSettings['useStdWrap']) && !empty($originalSettings['useStdWrap'])) {
$typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
$typoScriptArray = $typoScriptService->convertPlainArrayToTypoScriptArray($originalSettings);
$stdWrapProperties = GeneralUtility::trimExplode(',', $originalSettings['useStdWrap'], true);
foreach ($stdWrapProperties as $key) {
if (is_array($typoScriptArray[$key . '.'])) {
$originalSettings[$key] = $this->configurationManager->getContentObject()->stdWrap(
$typoScriptArray[$key],
$typoScriptArray[$key . '.']
);
}
}
}
lib.loadSimplepoll123 < lib.loadSimplepoll
lib.loadSimplepoll123.settings.simplepoll.uid = 123
lib.loadSimplepoll234 < lib.loadSimplepoll
lib.loadSimplepoll234.settings.simplepoll.uid = 234
lib.loadSimplepoll345 < lib.loadSimplepoll
lib.loadSimplepoll345.settings.simplepoll.uid = 345
lib.loadSimplepoll456 < lib.loadSimplepoll
lib.loadSimplepoll456.settings.simplepoll.uid = 456
<f:cObject typoscriptObjectPath="lib.loadSimplepoll{newsItem.simplepoll}" />
<?php
namespace Vendor\Extension\ViewHelpers;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class LoadSimplepollViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
{
/**
* @return void
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('simplepollUid', 'int', 'Uid of simplepoll', false);
}
/**
* @return string
*/
public function render()
{
$configurationManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
$simplepollTs = $configurationManager->getConfiguration(
\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS,
'simplepoll',
'Polllisting');
$cObj = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer');
$renderObjName = '<tt_content.list.20.simplepoll_polllisting';
$renderObjConf = $GLOBALS['TSFE']->tmpl->setup['tt_content.']['list.']['20.']['simplepoll_polllisting.'];
$renderObjConf['settings'] = $simplepollTs;
$renderObjConf['settings']['simplepoll']['uid'] = (int)$this->arguments['simplepollUid'];
return $cObj->cObjGetSingle($renderObjName, $renderObjConf);
}
}
{vh:LoadSimplepoll(simplepollUid: '{newsItem.ipgSimplepoll}')}