gpt4 book ai didi

TYPO3:通过 Typoscript 或 ViewHelper 呈现插件并更改设置

转载 作者:行者123 更新时间:2023-12-01 08:29:39 27 4
gpt4 key购买 nike

我想根据一些数据动态加载一个插件。首先,我尝试使用 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>

在弄清楚无法更改设置后,我尝试了一个 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);
}
}

viehelper 是这样调用的:

{vh:LoadSimplepoll(uid: '{newsItem.simplepoll}')}

现在我可以用这一行更改投票的 uid:$renderObjConf['settings']['simplepoll']['uid'] = $uid;

我现在的问题是,它会加载投票,但不会加载答案。我追踪到这个事实,插件不知何故不再知道 Record Storage Page$renderObjConf['persistence']['storagePid'] = 394; 行没有帮助。

我如何告诉插件 Storage Pid

或者是否有另一种/更好的方法来加载具有变化数据的插件?

最佳答案

为什么不能修改打字错误中的 settings.simplepoll.uid

因为扩展程序 simplepoll 不处理任何 stdWrap 功能到它的 typoscript 设置。

查看代码:
这个特殊设置用于 here :

$simplePoll = $this->simplePollRepository->findByUid($this->settings['simplepoll']['uid']);

没有 stdWrap,只是简单的用法。

将它与 ext:news 进行比较:

在使用任何设置之前,它会被处理。 typoscript 设置与插件中的设置的专用连接。如果有必要,可以使用 stdWrap:here

    $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 . '.']
);
}
}
}

如你所见:
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

然后像这样调用它

<f:cObject typoscriptObjectPath="lib.loadSimplepoll{newsItem.simplepoll}" />

或者您构建一个实现 stdWrap 功能的拉取请求并将其发送给扩展作者。

关于TYPO3:通过 Typoscript 或 ViewHelper 呈现插件并更改设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55000749/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com