plugin.tx_xxx {
setting {
storagePid = 23
}
}
I want this TYPO3 settings in utility file. Please help me.
plugin.tx_xxx {
setting {
storagePid = 23
}
}
I want this TYPO3 settings in utility file. Please help me.
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'];
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
currentPageId
is protected
and has no public setter for this. –
Resilience 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.
$settings = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS);
, you don't need the full TS. –
Mellisa $settings
property. The question is about Utlity classes, or Scheduler tasks, etc, there it is much more complicated. –
Resilience 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);
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'];
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.
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);
$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'];
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.
© 2022 - 2024 — McMap. All rights reserved.
ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK
for only the configuration of the current plugin. – Monamonachal