TYPO3:通过Typoscript或ViewHelper渲染插件并更改设置

问题描述 投票:1回答:3

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

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

typo3 typoscript extbase view-helpers
3个回答
0
投票

为什么不能在typoscript中修改settings.simplepoll.uid

因为扩展simplepoll不处理其typoscript设置的任何stdWrap功能。

看看代码: 这个特殊设置使用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不支持使用typoscript 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功能的pull请求并将其发送给扩展作者。


0
投票

为什么不能在typoscript中修改settings.simplepoll.uid? 你只需要正确的结构来修改它。

对于单个值,您可以使用current,但正确使用它。这是一个需要评估的stdWrap函数。 如果默认情况下没有stdWrap评估它可能适用于cObject类型的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>

和typoscript:

lib.arraytest = COA
lib.arraytest {
  10 = TEXT
  10.field = a
  10.wrap = /|/

  20 = TEXT
  20.field = b
  20.wrap = \|\
}

这导致/abc/\xyz\的输出。请注意:f:cobject标记的内部文本将丢失,因为数据参数优先于inner children


0
投票

与此同时,我让Viewhelpter工作:

视图助手:

<?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);
    }
}

在模板中调用viewhelper(不要忘记注册命名空间):

{vh:LoadSimplepoll(simplepollUid: '{newsItem.ipgSimplepoll}')}

而已。

© www.soinside.com 2019 - 2024. All rights reserved.