c516bf228b1fb21a5d259d171734cc72cbd04045
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Controller / ConfigurationController.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Susanne Moog, <typo3@susannemoog.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 use TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException;
30
31 /**
32 * Controller for configuration related actions.
33 *
34 * @author Susanne Moog <typo3@susannemoog.de>
35 */
36 class ConfigurationController extends \TYPO3\CMS\Extensionmanager\Controller\AbstractController {
37
38 /**
39 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ConfigurationItemRepository
40 * @inject
41 */
42 protected $configurationItemRepository;
43
44 /**
45 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
46 * @inject
47 */
48 protected $extensionRepository;
49
50 /**
51 * Show the extension configuration form. The whole form field handling is done
52 * in the corresponding view helper
53 *
54 * @param array $extension Extension information, must contain at least the key
55 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
56 * @return void
57 */
58 public function showConfigurationFormAction(array $extension) {
59 if (!array_key_exists('key', $extension)) {
60 throw new ExtensionManagerException(
61 'Extension key not found.',
62 1359206803
63 );
64 }
65 $configuration = $this->configurationItemRepository->findByExtensionKey($extension['key']);
66 if ($configuration) {
67 $this->view
68 ->assign('configuration', $configuration)
69 ->assign('extension', $extension);
70 } else {
71 /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension */
72 $extension = $this->extensionRepository->findOneByCurrentVersionByExtensionKey($extension['key']);
73 // Extension has no configuration and is a distribution
74 if ($extension->getCategory() === \TYPO3\CMS\Extensionmanager\Domain\Model\Extension::DISTRIBUTION_CATEGORY) {
75 $this->redirect('welcome', 'Distribution', NULL, array('extension' => $extension->getUid()));
76 }
77 throw new ExtensionManagerException('The extension ' . htmlspecialchars($extension['key']) . ' has no configuration.');
78 }
79 }
80
81 /**
82 * Save configuration to file
83 * Merges existing with new configuration.
84 *
85 * @param array $config The new extension configuration
86 * @param string $extensionKey The extension key
87 * @return void
88 */
89 public function saveAction(array $config, $extensionKey) {
90 /** @var $configurationUtility \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility */
91 $configurationUtility = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\ConfigurationUtility');
92 $currentFullConfiguration = $configurationUtility->getCurrentConfiguration($extensionKey);
93 $newConfiguration = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($currentFullConfiguration, $config);
94 $configurationUtility->writeConfiguration(
95 $configurationUtility->convertValuedToNestedConfiguration($newConfiguration),
96 $extensionKey
97 );
98 $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionConfigurationWrite', array($newConfiguration, $this));
99 /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension */
100 $extension = $this->extensionRepository->findOneByCurrentVersionByExtensionKey($extensionKey);
101 // Different handling for distribution installation
102 if ($extension->getCategory() === \TYPO3\CMS\Extensionmanager\Domain\Model\Extension::DISTRIBUTION_CATEGORY) {
103 $this->redirect('welcome', 'Distribution', NULL, array('extension' => $extension->getUid()));
104 } else {
105 $this->redirect('showConfigurationForm', NULL, NULL, array('extension' => array('key' => $extensionKey)));
106 }
107 }
108
109 }
110
111
112 ?>