TYPO3 CMS  TYPO3_7-6
ConfigurationController.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
23 
28 {
33 
38 
42  public function injectConfigurationItemRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ConfigurationItemRepository $configurationItemRepository)
43  {
44  $this->configurationItemRepository = $configurationItemRepository;
45  }
46 
50  public function injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository)
51  {
52  $this->extensionRepository = $extensionRepository;
53  }
54 
61  protected function initializeView(ViewInterface $view)
62  {
63  if ($view instanceof BackendTemplateView) {
65  parent::initializeView($view);
66  $this->generateMenu();
67  $this->registerDocheaderButtons();
68  }
69  }
70 
79  public function showConfigurationFormAction(array $extension)
80  {
81  if (!isset($extension['key'])) {
82  throw new ExtensionManagerException('Extension key not found.', 1359206803);
83  }
84  $extKey = $extension['key'];
85  $configuration = $this->configurationItemRepository->findByExtensionKey($extKey);
86  if ($configuration) {
87  $this->view
88  ->assign('configuration', $configuration)
89  ->assign('extension', $extension);
90  } else {
92  $extension = $this->extensionRepository->findOneByCurrentVersionByExtensionKey($extKey);
93  // Extension has no configuration and is a distribution
94  if ($extension->getCategory() === Extension::DISTRIBUTION_CATEGORY) {
95  $this->redirect('welcome', 'Distribution', null, ['extension' => $extension->getUid()]);
96  }
97  throw new ExtensionManagerException('The extension ' . $extKey . ' has no configuration.');
98  }
99  }
100 
109  public function saveAction(array $config, $extensionKey)
110  {
111  $this->saveConfiguration($config, $extensionKey);
113  $extension = $this->extensionRepository->findOneByCurrentVersionByExtensionKey($extensionKey);
114  // Different handling for distribution installation
115  if ($extension instanceof Extension &&
117  ) {
118  $this->redirect('welcome', 'Distribution', null, ['extension' => $extension->getUid()]);
119  } else {
120  $this->redirect('showConfigurationForm', null, null, ['extension' => ['key' => $extensionKey]]);
121  }
122  }
123 
131  public function saveAndCloseAction(array $config, $extensionKey)
132  {
133  $this->saveConfiguration($config, $extensionKey);
134  $this->redirect('index', 'List');
135  }
136 
144  protected function emitAfterExtensionConfigurationWriteSignal($extensionKey, array $newConfiguration)
145  {
146  $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionConfigurationWrite', [$extensionKey, $newConfiguration, $this]);
147  }
148 
156  protected function saveConfiguration(array $config, $extensionKey)
157  {
159  $configurationUtility = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class);
160  $newConfiguration = $configurationUtility->getCurrentConfiguration($extensionKey);
162  $configurationUtility->writeConfiguration(
163  $configurationUtility->convertValuedToNestedConfiguration($newConfiguration),
164  $extensionKey
165  );
166  $this->emitAfterExtensionConfigurationWriteSignal($extensionKey, $newConfiguration);
167  }
168 
175  protected function registerDocheaderButtons()
176  {
177  $moduleTemplate = $this->view->getModuleTemplate();
178  $lang = $this->getLanguageService();
179 
181  $buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
182 
183  $uriBuilder = $this->controllerContext->getUriBuilder();
184  $uri = $uriBuilder->reset()->uriFor('index', [], 'List');
185 
186  $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL);
187  $goBackButton = $buttonBar->makeLinkButton()
188  ->setHref($uri)
189  ->setTitle($this->translate('extConfTemplate.backToList'))
190  ->setIcon($icon);
191  $buttonBar->addButton($goBackButton, ButtonBar::BUTTON_POSITION_LEFT);
192 
193  $saveSplitButton = $buttonBar->makeSplitButton();
194  // SAVE button:
195  $saveButton = $buttonBar->makeInputButton()
196  ->setName('_savedok')
197  ->setValue('1')
198  ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc'))
199  ->setForm('configurationform')
200  ->setIcon($moduleTemplate->getIconFactory()->getIcon('actions-document-save', Icon::SIZE_SMALL));
201  $saveSplitButton->addItem($saveButton, true);
202 
203  // SAVE / CLOSE
204  $saveAndCloseButton = $buttonBar->makeInputButton()
205  ->setName('_saveandclosedok')
206  ->setClasses('t3js-save-close')
207  ->setValue('1')
208  ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc'))
209  ->setForm('configurationform')
210  ->setIcon($moduleTemplate->getIconFactory()->getIcon(
211  'actions-document-save-close',
213  ));
214  $saveSplitButton->addItem($saveAndCloseButton);
215  $buttonBar->addButton($saveSplitButton, ButtonBar::BUTTON_POSITION_LEFT, 2);
216  }
217 
221  protected function getLanguageService()
222  {
223  return $GLOBALS['LANG'];
224  }
225 }
injectConfigurationItemRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ConfigurationItemRepository $configurationItemRepository)
emitAfterExtensionConfigurationWriteSignal($extensionKey, array $newConfiguration)
redirect($actionName, $controllerName=null, $extensionName=null, array $arguments=null, $pageUid=null, $delay=0, $statusCode=303)
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']