skip to Main Content

Since TYPO3 itself does not support custom feature toggles in the backend, I wanted to build my own implementation for this.
I looked at the ConfigurationManager.php and it says in the comment at the top:
‘This class is intended for internal core use ONLY.

  • Extensions should usually use the resulting $GLOBALS[‘TYPO3_CONF_VARS’] array,
  • do not try to modify settings in LocalConfiguration.php with an extension.’

But if I now try to edit the globals in my action:
$GLOBALS['TYPO3_CONF_VARS']['SYS']['features'][$feature] = !$GLOBALS['TYPO3_CONF_VARS']['SYS']['features'][$feature];
The value only changes for a short time and after I reload the page, the value is reset again.

Am I missing something or is there another value I could go for?

2

Answers


  1. Edit Your typoscript with this

    plugin.tx_myextension {
        settings {
            enableFeature = 1
        }
    }
    

    yourfile.php

        $featureToggle = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_myextension.']['settings.']['enableFeature'];
    
    // ext_localconf.php
    $featureToggle = TYPO3CMSCoreUtilityGeneralUtility::makeInstance(TYPO3CMSCoreConfigurationExtensionConfiguration::class)
        ->get('myextension')['enableFeature'];
    
    if ($featureToggle) {
        // Your feature is enabled
    } else {
        // Your feature is disabled
    }
    
    Login or Signup to reply.
  2. I made my own feature toggle in this way.

    An on/off switch as an extension configuration in ext_conf_template.txt

    # cat=feature toggle/enable/10; type=boolean; label=use feature
    myFeature = 0
    

    Save it, ext_localconf.php

    // Register feature toggle
    if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['myFeature'])) {
        $myFeature = GeneralUtility::makeInstance(ExtensionConfiguration::class)
            ->get('myext', 'myFeature');
        if ($myFeature) {
            $GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['myFeature'] = true;
        } else {
            $GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['myFeature'] = false;
        }
    }
    

    Use it in controller

        if (GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('myFeature')) {
            $this->view->assign('myFeature', true);
        }
    

    In templates

    <f:if condition="{myFeature} == true">
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search