Search code examples
dependency-injectiontypo3typoscript

TYPO3 - Retrieved TypoScript in itemsProcFunc are incomplete


I have following problem: We are overriding the tt_content TCA with a custom column which has an itemsProcFunc in it's config. In the function we try to retrieve the TypoScript-Settings, so we can display the items dynamically. The problem is: In the function we don't receive all the TypoScript-Settings, which are included but only some.

'itemsProcFunc' => 'Vendor\Ext\Backend\Hooks\TcaHook->addFields',

class TcaHook
{

        public function addFields($config){
            $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
            $configurationManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');

            $setup = $configurationManager->getConfiguration(
                \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT
            );
        }

$setup is now incomplete and doesn't contain the full TypoScript, for example some of the static-included TypoScript is missing.

Used TYPO3 7 LTS (7.6.18), PHP 7.0.* in composer-mode.

Does anybody know where the problem is? Is there some alternative?


Solution

  • You maybe misunderstood the purpose of TypoScipt. It is a way of configuration for the Frontend. The Hook you mentioned is used in the TCA, whích is a Backend part of TYPO3. TypoScript usually isn't used for backend related stuff at all, because it is bound to a specific page template record. Instead in the backend, there is the TSConfig, that can be bound to a page, but also can be added globally. Another thing you are doing wrong is the use of the ObjectManager and the ConfigurationManager, which are classes of extbase, which isn't initialized in the backend. I would recommend to not use extbase in TCA, because the TCA is cached and loaded for every page request. Instead use TSConfig or give your configuration settings directly to the TCA. Do not initialize extbase and do not use extbase classes in these hooks. Depending on what you want to configure via TypoScript, you may want to do something like this:

    'config' => [
        'type' => 'select',
        'renderType' => 'singleSelect',
        'items' => [
            ['EXT:my_ext/Resources/Private/Language/locallang_db.xlf:myfield.I.0', '']
        ],
        'itemsProcFunc' => \VENDOR\MyExt\UserFunctions\FormEngine\TypeSelectProcFunc::class . '->fillSelect',
        'customSetting' => 'somesetting'
    ]
    

    and then access it in your class:

    class TypeSelectProcFunc{
        public function fillSelect(&$params){
            if( $params['customSetting'] === 'somesetting' ){
                $params['items'][] = ['New item',1];
            }
        }
    }