TYPO3  7.6
ConfigurationController.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Controller;
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, array('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 &&
116  $extension->getCategory() === Extension::DISTRIBUTION_CATEGORY
117  ) {
118  $this->redirect('welcome', 'Distribution', null, array('extension' => $extension->getUid()));
119  } else {
120  $this->redirect('showConfigurationForm', null, null, array('extension' => array('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 
137 
145  protected function emitAfterExtensionConfigurationWriteSignal($extensionKey, array $newConfiguration)
146  {
147  $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionConfigurationWrite', array($extensionKey, $newConfiguration, $this));
148  }
149 
157  protected function saveConfiguration(array $config, $extensionKey)
158  {
160  $configurationUtility = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class);
161  $newConfiguration = $configurationUtility->getCurrentConfiguration($extensionKey);
162  \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($newConfiguration, $config);
163  $configurationUtility->writeConfiguration(
164  $configurationUtility->convertValuedToNestedConfiguration($newConfiguration),
165  $extensionKey
166  );
167  $this->emitAfterExtensionConfigurationWriteSignal($extensionKey, $newConfiguration);
168  }
169 
176  protected function registerDocheaderButtons()
177  {
178  $moduleTemplate = $this->view->getModuleTemplate();
179  $lang = $this->getLanguageService();
180 
182  $buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
183 
184  $uriBuilder = $this->controllerContext->getUriBuilder();
185  $uri = $uriBuilder->reset()->uriFor('index', [], 'List');
186 
187  $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL);
188  $goBackButton = $buttonBar->makeLinkButton()
189  ->setHref($uri)
190  ->setTitle($this->translate('extConfTemplate.backToList'))
191  ->setIcon($icon);
192  $buttonBar->addButton($goBackButton, ButtonBar::BUTTON_POSITION_LEFT);
193 
194  $saveSplitButton = $buttonBar->makeSplitButton();
195  // SAVE button:
196  $saveButton = $buttonBar->makeInputButton()
197  ->setName('_savedok')
198  ->setValue('1')
199  ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', true))
200  ->setForm('configurationform')
201  ->setIcon($moduleTemplate->getIconFactory()->getIcon('actions-document-save', Icon::SIZE_SMALL));
202  $saveSplitButton->addItem($saveButton, true);
203 
204  // SAVE / CLOSE
205  $saveAndCloseButton = $buttonBar->makeInputButton()
206  ->setName('_saveandclosedok')
207  ->setClasses('t3js-save-close')
208  ->setValue('1')
209  ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', true))
210  ->setForm('configurationform')
211  ->setIcon($moduleTemplate->getIconFactory()->getIcon(
212  'actions-document-save-close',
214  ));
215  $saveSplitButton->addItem($saveAndCloseButton);
216  $buttonBar->addButton($saveSplitButton, ButtonBar::BUTTON_POSITION_LEFT, 2);
217  }
218 
222  protected function getLanguageService()
223  {
224  return $GLOBALS['LANG'];
225  }
226 }