Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TYPO3: Render a plugin via Typoscript or ViewHelper and change settings

I would like to load a plugin dynamically according to some data. First I tried to do it with Typoscript, but after some research I figured out, that it is not possible to change the settings of the plugin (see old forum entry).

I need to change settings.simplepoll.uid according to the passed data:

This is the Typoscript I tried:

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
        }
    }
}

The call in the template looks like that:

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

After figuring out, that changing the settings is not possible, I tried a 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);
    }
}

The viehelper is called like this:

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

Now I am able to change the uid of the poll with this line: $renderObjConf['settings']['simplepoll']['uid'] = $uid;

My problem is now, that it loads the poll, but not the answers. I tracked this down to the fact, that the plugin somehow does not know the Record Storage Page anymore. The line $renderObjConf['persistence']['storagePid'] = 394; does not help.

How can I tell the plugin the Storage Pid?

Or is there another/better way to load a plugin with changing data?

like image 298
chris Avatar asked Dec 09 '25 19:12

chris


1 Answers

Why shouldn't it be possible to modify settings.simplepoll.uid in typoscript?

because the extension simplepoll does not handle any stdWrap functionality to its typoscript settings.

Have a look into the code:
this special setting is used here:

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

no stdWrap, just plain usage.

compare it to ext:news:

before any settings is used it is processed. A dedicated join of typoscript settings with the settings in the plugin. And if necessary there is a stdWrap possible: 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 . '.']
                );
            }
        }
    }

As you can see:
extbase does not support you with typoscript stdWrap functionality.
You (and every extension author) need to do it by hand. But that was so even before extbase.

In this way: as you can not configure your value you only can trick TYPO3 (and the plugin):
if you have a small number of uids you can have one variant for each 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

and call it like

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

or you build a pull request implementing the stdWrap functionality and send it to the extension author.

like image 192
Bernd Wilke πφ Avatar answered Dec 12 '25 01:12

Bernd Wilke πφ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!