How to get TYPO3 settings in the utility files?

18.9k views Asked by At
plugin.tx_xxx {
    setting {
        storagePid = 23
    } 
}

I want this TYPO3 settings in utility file. Please help me.

7

There are 7 answers

1
Bharat Parmar On BEST ANSWER

The above method works only in controller or services class try below it will work in any PHP files in Extension.

$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\Extbase\\Object\\ObjectManager');
$configurationManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
$extbaseFrameworkConfiguration = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
$storagePid = $extbaseFrameworkConfiguration['plugin.']['tx_guesthouse_guesthouse.']['settings.']['storagePid'];
3
Vishal Tanna On

You can add below line in the your controller.

$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');    
$configurationManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
$setting = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS);   
$ts_config = $setting['plugin.']['tx_xxxx.']['settings.']['storagePid'];

I think it will helpful to you. You can also used this typo3 settings in the services files as well.

2
Mihir Bhatt On

Only for TYPO3 Backend

For multi domain set root before obtaining configuration

$configurationManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Configuration\\BackendConfigurationManager');
$configurationManager->currentPageId = ROOT_PID_OF_YOUR_DOMAIN;
$extbaseFrameworkConfiguration = $configurationManager->getTypoScriptSetup();

//Following will be resultant array, find your required stuff from it
print_r($extbaseFrameworkConfiguration);

Note: Don't forget to extend your class with \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager in order to obtain access for it's protected variables

0
Gauri On

Now,In Typo3 8.X, currentPageId is protected so, we could not set it directly, and there would not be any set method defined in core class. Following is correct code as per new version that may help you. Thanks for the correct direction.

$configurationManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Configuration\\BackendConfigurationManager');
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($configurationManager);
$configurationManager->getDefaultBackendStoragePid(); 
$extbaseFrameworkConfiguration = $configurationManager->getTypoScriptSetup();

//Following will be resultant array, find your required stuff from it
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($extbaseFrameworkConfiguration);
0
rantanplan On

You can also only load the CONFIGURATION_TYPE_SETTINGS:

  $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\Extbase\\Object\\ 
ObjectManager');
  $configurationManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
  $pluginSettings = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, null, 'tx_guesthouse_guesthouse');
  $storagePid = $pluginSettings['storagePid'];

IMHO this is more effective because it does not load the whole TS tree.

0
biesior On

A little bit late to the party, but there is also 99° Helpers for TYPO3 extension, which contains methods for fetching TS. i.e.

\nn\t3::Settings()->getFullTyposcript($pid = NULL);

Sample one-liners would look like (note: without trailing dots!):
$mySettings = \nn\t3::Settings()->getFullTyposcript()
                      ['plugin']['tx_myext_myplugin']['settings'];

or even, single value:

$storagePid = \nn\t3::Settings()->getFullTyposcript()
                      ['plugin']['tx_myext_myplugin']['settings']['storagePid'];
de facto

this method is just a wrapper for ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT approach suggested in other answer, and you don't need to install a whole large toolbox for one, simple thing, but if someone already uses 99° Helpers (really nice thing IMHO) can use it within seconds. Bonus tip: mentioned method uses internal caching to make things even faster.

0
John Miller On

In any TYPO3 version including 10, one may use this one-liner:

$GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_xxxx.']['settings.']['storagePid'];

To get rid of the dots, use TypoScriptService, thus

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;

$typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
$typoScriptSettings = $typoScriptService->convertTypoScriptArrayToPlainArray($GLOBALS['TSFE']->tmpl->setup);
    
$storagePid = $typoScriptSettings['plugin']['tx_xxxx']['settings']['storagePid'];