TYPO3 CMS  TYPO3_6-2
ConfigurationUtility.php
Go to the documentation of this file.
1 <?php
3 
22 
27  protected $objectManager;
28 
38  public function saveDefaultConfiguration($extensionKey) {
39  $currentConfiguration = $this->getCurrentConfiguration($extensionKey);
40  $nestedConfiguration = $this->convertValuedToNestedConfiguration($currentConfiguration);
41  $this->writeConfiguration($nestedConfiguration, $extensionKey);
42  }
43 
57  public function writeConfiguration(array $configuration = array(), $extensionKey) {
59  $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
60  $configurationManager->setLocalConfigurationValueByPath('EXT/extConf/' . $extensionKey, serialize($configuration));
61  \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroup('system');
62  }
63 
70  public function getCurrentConfiguration($extensionKey) {
71  $mergedConfiguration = $this->getDefaultConfigurationFromExtConfTemplateAsValuedArray($extensionKey);
72  $currentExtensionConfig = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey]);
73  $currentExtensionConfig = is_array($currentExtensionConfig) ? $currentExtensionConfig : array();
74  $currentExtensionConfig = $this->convertNestedToValuedConfiguration($currentExtensionConfig);
76  $mergedConfiguration,
77  $currentExtensionConfig
78  );
79  return $mergedConfiguration;
80  }
81 
110  $rawConfigurationString = $this->getDefaultConfigurationRawString($extensionKey);
111 
112  $theConstants = array();
113 
114  if (strlen($rawConfigurationString) > 0) {
115  $extensionPathInformation = $this->getExtensionPathInformation($extensionKey);
116 
117  $tsStyleConfig = $this->objectManager->get('TYPO3\\CMS\\Core\\TypoScript\\ConfigurationForm');
118  $tsStyleConfig->doNotSortCategoriesBeforeMakingForm = TRUE;
119 
120  $theConstants = $tsStyleConfig->ext_initTSstyleConfig(
121  $rawConfigurationString,
122  $extensionPathInformation['siteRelPath'],
123  PATH_site . $extensionPathInformation['siteRelPath'],
124  $GLOBALS['BACK_PATH']
125  );
126 
127  // Loop through configuration items, see if it is assigned to a sub category
128  // and add the sub category label to the item property if so.
129  foreach ($theConstants as $configurationOptionName => $configurationOption) {
130  if (
131  array_key_exists('subcat_name', $configurationOption)
132  && isset($tsStyleConfig->subCategories[$configurationOption['subcat_name']])
133  && isset($tsStyleConfig->subCategories[$configurationOption['subcat_name']][0])
134  ) {
135  $theConstants[$configurationOptionName]['subcat_label'] = $tsStyleConfig->subCategories[$configurationOption['subcat_name']][0];
136  }
137  }
138 
139  // Set up the additional descriptions
140  if (isset($tsStyleConfig->setup['constants']['TSConstantEditor.'])) {
141  foreach ($tsStyleConfig->setup['constants']['TSConstantEditor.'] as $category => $highlights) {
142  $theConstants['__meta__'][rtrim($category, '.')]['highlightText'] = $highlights['description'];
143  foreach ($highlights as $highlightNumber => $value) {
144  if (rtrim($category, '.') == $theConstants[$value]['cat']) {
145  $theConstants[$value]['highlight'] = $highlightNumber;
146  }
147  }
148  }
149  }
150  }
151 
152  return $theConstants;
153  }
154 
159  protected function getExtensionPathInformation($extensionKey) {
160  return $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey];
161  }
162 
170  protected function getDefaultConfigurationRawString($extensionKey) {
171  $rawString = '';
172  $extConfTemplateFileLocation = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName(
173  'EXT:' . $extensionKey . '/ext_conf_template.txt',
174  FALSE
175  );
176  if (file_exists($extConfTemplateFileLocation)) {
177  $rawString = file_get_contents($extConfTemplateFileLocation);
178  }
179  return $rawString;
180  }
181 
192  public function convertValuedToNestedConfiguration(array $valuedConfiguration) {
193  $nestedConfiguration = array();
194  foreach ($valuedConfiguration as $name => $section) {
195  $path = str_replace('.', './', $name);
196  $nestedConfiguration = \TYPO3\CMS\Core\Utility\ArrayUtility::setValueByPath($nestedConfiguration, $path, $section['value'], '/');
197  }
198  return $nestedConfiguration;
199  }
200 
210  public function convertNestedToValuedConfiguration(array $nestedConfiguration) {
211  $flatExtensionConfig = \TYPO3\CMS\Core\Utility\ArrayUtility::flatten($nestedConfiguration);
212  $valuedCurrentExtensionConfig = array();
213  foreach ($flatExtensionConfig as $key => $value) {
214  $valuedCurrentExtensionConfig[$key]['value'] = $value;
215  }
216  return $valuedCurrentExtensionConfig;
217  }
218 }
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=TRUE, $includeEmptyValues=TRUE, $enableUnsetFeature=TRUE)
static setValueByPath(array $array, $path, $value, $delimiter='/')
static flatten(array $array, $prefix='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static getFileAbsFileName($filename, $onlyRelative=TRUE, $relToTYPO3_mainDir=FALSE)