[BUGFIX] Ensure manually updated slug is saved correctly
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Configuration / ConfigurationManager.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Extbase\Configuration;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 /**
20 * A configuration manager following the strategy pattern (GoF315). It hides the concrete
21 * implementation of the configuration manager and provides an unified access point.
22 *
23 * Use the shutdown() method to drop the concrete implementation.
24 * @internal only to be used within Extbase, not part of TYPO3 Core API.
25 */
26 class ConfigurationManager implements \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
27 {
28 /**
29 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
30 */
31 protected $objectManager;
32
33 /**
34 * @var \TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager
35 */
36 protected $concreteConfigurationManager;
37
38 /**
39 * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
40 */
41 protected $environmentService;
42
43 /**
44 * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
45 * @param \TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService
46 */
47 public function __construct(
48 \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager,
49 \TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService
50 ) {
51 $this->objectManager = $objectManager;
52 $this->environmentService = $environmentService;
53
54 $this->initializeConcreteConfigurationManager();
55 }
56
57 protected function initializeConcreteConfigurationManager(): void
58 {
59 if ($this->environmentService->isEnvironmentInFrontendMode()) {
60 $this->concreteConfigurationManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager::class);
61 } else {
62 $this->concreteConfigurationManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class);
63 }
64 }
65
66 /**
67 * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject
68 */
69 public function setContentObject(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject): void
70 {
71 $this->concreteConfigurationManager->setContentObject($contentObject);
72 }
73
74 /**
75 * @return \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer|null
76 */
77 public function getContentObject(): ?\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
78 {
79 return $this->concreteConfigurationManager->getContentObject();
80 }
81
82 /**
83 * Sets the specified raw configuration coming from the outside.
84 * Note that this is a low level method and only makes sense to be used by Extbase internally.
85 *
86 * @param array $configuration The new configuration
87 */
88 public function setConfiguration(array $configuration = []): void
89 {
90 $this->concreteConfigurationManager->setConfiguration($configuration);
91 }
92
93 /**
94 * Returns the specified configuration.
95 * The actual configuration will be merged from different sources in a defined order.
96 *
97 * You can get the following types of configuration invoking:
98 * CONFIGURATION_TYPE_SETTINGS: Extbase settings
99 * CONFIGURATION_TYPE_FRAMEWORK: the current module/plugin settings
100 * CONFIGURATION_TYPE_FULL_TYPOSCRIPT: a raw TS array
101 *
102 * Note that this is a low level method and only makes sense to be used by Extbase internally.
103 *
104 * @param string $configurationType The kind of configuration to fetch - must be one of the CONFIGURATION_TYPE_* constants
105 * @param string $extensionName if specified, the configuration for the given extension will be returned.
106 * @param string $pluginName if specified, the configuration for the given plugin will be returned.
107 * @throws Exception\InvalidConfigurationTypeException
108 * @return array The configuration
109 */
110 public function getConfiguration(string $configurationType, string $extensionName = null, string $pluginName = null): array
111 {
112 switch ($configurationType) {
113 case self::CONFIGURATION_TYPE_SETTINGS:
114 $configuration = $this->concreteConfigurationManager->getConfiguration($extensionName, $pluginName);
115 return $configuration['settings'] ?? [];
116 case self::CONFIGURATION_TYPE_FRAMEWORK:
117 return $this->concreteConfigurationManager->getConfiguration($extensionName, $pluginName);
118 case self::CONFIGURATION_TYPE_FULL_TYPOSCRIPT:
119 return $this->concreteConfigurationManager->getTypoScriptSetup();
120 default:
121 throw new \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException('Invalid configuration type "' . $configurationType . '"', 1206031879);
122 }
123 }
124
125 /**
126 * Returns TRUE if a certain feature, identified by $featureName
127 * should be activated, FALSE for backwards-compatible behavior.
128 *
129 * This is an INTERNAL API used throughout Extbase and Fluid for providing backwards-compatibility.
130 * Do not use it in your custom code!
131 *
132 * @param string $featureName
133 * @return bool
134 */
135 public function isFeatureEnabled(string $featureName): bool
136 {
137 $configuration = $this->getConfiguration(self::CONFIGURATION_TYPE_FRAMEWORK);
138 return (bool)(isset($configuration['features'][$featureName]) && $configuration['features'][$featureName]);
139 }
140 }